Skip to content

Commit

Permalink
chore: address clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Aug 7, 2024
1 parent e4e4bb7 commit d7d9000
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 59 deletions.
5 changes: 0 additions & 5 deletions actix-router/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,6 @@ mod tests {
value: String,
}

#[derive(Deserialize)]
struct Id {
_id: String,
}

#[derive(Debug, Deserialize)]
struct Test1(String, u32);

Expand Down
36 changes: 2 additions & 34 deletions actix-web/benches/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ use std::{future::Future, time::Instant};

use actix_http::body::BoxBody;
use actix_utils::future::{ready, Ready};
use actix_web::{
error, http::StatusCode, test::TestRequest, Error, HttpRequest, HttpResponse, Responder,
};
use actix_web::{http::StatusCode, test::TestRequest, Error, HttpRequest, HttpResponse, Responder};
use criterion::{criterion_group, criterion_main, Criterion};
use futures_util::future::{join_all, Either};
use futures_util::future::join_all;

// responder simulate the old responder trait.
trait FutureResponder {
Expand All @@ -16,9 +14,6 @@ trait FutureResponder {
fn future_respond_to(self, req: &HttpRequest) -> Self::Future;
}

// a simple option responder type.
struct OptionResponder<T>(Option<T>);

// a simple wrapper type around string
struct StringResponder(String);

Expand All @@ -34,22 +29,6 @@ impl FutureResponder for StringResponder {
}
}

impl<T> FutureResponder for OptionResponder<T>
where
T: FutureResponder,
T::Future: Future<Output = Result<HttpResponse, Error>>,
{
type Error = Error;
type Future = Either<T::Future, Ready<Result<HttpResponse, Self::Error>>>;

fn future_respond_to(self, req: &HttpRequest) -> Self::Future {
match self.0 {
Some(t) => Either::Left(t.future_respond_to(req)),
None => Either::Right(ready(Err(error::ErrorInternalServerError("err")))),
}
}
}

impl Responder for StringResponder {
type Body = BoxBody;

Expand All @@ -60,17 +39,6 @@ impl Responder for StringResponder {
}
}

impl<T: Responder> Responder for OptionResponder<T> {
type Body = BoxBody;

fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body> {
match self.0 {
Some(t) => t.respond_to(req).map_into_boxed_body(),
None => HttpResponse::from_error(error::ErrorInternalServerError("err")),
}
}
}

fn future_responder(c: &mut Criterion) {
let rt = actix_rt::System::new();
let req = TestRequest::default().to_http_request();
Expand Down
2 changes: 1 addition & 1 deletion actix-web/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
/// 1. It is an async function (or a function/closure that returns an appropriate future);
/// 1. The function parameters (up to 12) implement [`FromRequest`];
/// 1. The async function (or future) resolves to a type that can be converted into an
/// [`HttpResponse`] (i.e., it implements the [`Responder`] trait).
/// [`HttpResponse`] (i.e., it implements the [`Responder`] trait).
///
///
/// # Compiler Errors
Expand Down
2 changes: 1 addition & 1 deletion actix-web/src/http/header/content_disposition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ impl Header for ContentDisposition {
}

fn parse<T: crate::HttpMessage>(msg: &T) -> Result<Self, crate::error::ParseError> {
if let Some(h) = msg.headers().get(&Self::name()) {
if let Some(h) = msg.headers().get(Self::name()) {
Self::from_raw(h)
} else {
Err(crate::error::ParseError::Header)
Expand Down
14 changes: 7 additions & 7 deletions actix-web/src/http/header/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,16 @@ impl ByteRangeSpec {
/// satisfiable if they meet the following conditions:
///
/// > If a valid byte-range-set includes at least one byte-range-spec with a first-byte-pos that
/// is less than the current length of the representation, or at least one
/// suffix-byte-range-spec with a non-zero suffix-length, then the byte-range-set
/// is satisfiable. Otherwise, the byte-range-set is unsatisfiable.
/// > is less than the current length of the representation, or at least one
/// > suffix-byte-range-spec with a non-zero suffix-length, then the byte-range-set is
/// > satisfiable. Otherwise, the byte-range-set is unsatisfiable.
///
/// The function also computes remainder ranges based on the RFC:
///
/// > If the last-byte-pos value is absent, or if the value is greater than or equal to the
/// current length of the representation data, the byte range is interpreted as the remainder
/// of the representation (i.e., the server replaces the value of last-byte-pos with a value
/// that is one less than the current length of the selected representation).
/// > current length of the representation data, the byte range is interpreted as the remainder
/// > of the representation (i.e., the server replaces the value of last-byte-pos with a value
/// > that is one less than the current length of the selected representation).
///
/// [RFC 7233 §2.1]: https://datatracker.ietf.org/doc/html/rfc7233
pub fn to_satisfiable_range(&self, full_length: u64) -> Option<(u64, u64)> {
Expand Down Expand Up @@ -270,7 +270,7 @@ impl Header for Range {

#[inline]
fn parse<T: HttpMessage>(msg: &T) -> Result<Self, ParseError> {
header::from_one_raw_str(msg.headers().get(&Self::name()))
header::from_one_raw_str(msg.headers().get(Self::name()))
}
}

Expand Down
12 changes: 2 additions & 10 deletions actix-web/src/middleware/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,11 +622,7 @@ impl FormatText {

FormatText::ResponseHeader(ref name) => {
let s = if let Some(val) = res.headers().get(name) {
if let Ok(s) = val.to_str() {
s
} else {
"-"
}
val.to_str().unwrap_or("-")
} else {
"-"
};
Expand Down Expand Up @@ -670,11 +666,7 @@ impl FormatText {
FormatText::RequestTime => *self = FormatText::Str(now.format(&Rfc3339).unwrap()),
FormatText::RequestHeader(ref name) => {
let s = if let Some(val) = req.headers().get(name) {
if let Ok(s) = val.to_str() {
s
} else {
"-"
}
val.to_str().unwrap_or("-")
} else {
"-"
};
Expand Down
2 changes: 1 addition & 1 deletion actix-web/src/response/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ mod tests {
// content type override
let res = HttpResponse::Ok()
.insert_header((CONTENT_TYPE, "text/json"))
.json(&vec!["v1", "v2", "v3"]);
.json(["v1", "v2", "v3"]);
let ct = res.headers().get(CONTENT_TYPE).unwrap();
assert_eq!(ct, HeaderValue::from_static("text/json"));
assert_body_eq!(res, br#"["v1","v2","v3"]"#);
Expand Down

0 comments on commit d7d9000

Please sign in to comment.