Skip to content

Commit d7d9000

Browse files
committed
chore: address clippy warnings
1 parent e4e4bb7 commit d7d9000

File tree

7 files changed

+14
-59
lines changed

7 files changed

+14
-59
lines changed

actix-router/src/de.rs

-5
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,6 @@ mod tests {
511511
value: String,
512512
}
513513

514-
#[derive(Deserialize)]
515-
struct Id {
516-
_id: String,
517-
}
518-
519514
#[derive(Debug, Deserialize)]
520515
struct Test1(String, u32);
521516

actix-web/benches/responder.rs

+2-34
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ use std::{future::Future, time::Instant};
22

33
use actix_http::body::BoxBody;
44
use actix_utils::future::{ready, Ready};
5-
use actix_web::{
6-
error, http::StatusCode, test::TestRequest, Error, HttpRequest, HttpResponse, Responder,
7-
};
5+
use actix_web::{http::StatusCode, test::TestRequest, Error, HttpRequest, HttpResponse, Responder};
86
use criterion::{criterion_group, criterion_main, Criterion};
9-
use futures_util::future::{join_all, Either};
7+
use futures_util::future::join_all;
108

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

19-
// a simple option responder type.
20-
struct OptionResponder<T>(Option<T>);
21-
2217
// a simple wrapper type around string
2318
struct StringResponder(String);
2419

@@ -34,22 +29,6 @@ impl FutureResponder for StringResponder {
3429
}
3530
}
3631

37-
impl<T> FutureResponder for OptionResponder<T>
38-
where
39-
T: FutureResponder,
40-
T::Future: Future<Output = Result<HttpResponse, Error>>,
41-
{
42-
type Error = Error;
43-
type Future = Either<T::Future, Ready<Result<HttpResponse, Self::Error>>>;
44-
45-
fn future_respond_to(self, req: &HttpRequest) -> Self::Future {
46-
match self.0 {
47-
Some(t) => Either::Left(t.future_respond_to(req)),
48-
None => Either::Right(ready(Err(error::ErrorInternalServerError("err")))),
49-
}
50-
}
51-
}
52-
5332
impl Responder for StringResponder {
5433
type Body = BoxBody;
5534

@@ -60,17 +39,6 @@ impl Responder for StringResponder {
6039
}
6140
}
6241

63-
impl<T: Responder> Responder for OptionResponder<T> {
64-
type Body = BoxBody;
65-
66-
fn respond_to(self, req: &HttpRequest) -> HttpResponse<Self::Body> {
67-
match self.0 {
68-
Some(t) => t.respond_to(req).map_into_boxed_body(),
69-
None => HttpResponse::from_error(error::ErrorInternalServerError("err")),
70-
}
71-
}
72-
}
73-
7442
fn future_responder(c: &mut Criterion) {
7543
let rt = actix_rt::System::new();
7644
let req = TestRequest::default().to_http_request();

actix-web/src/handler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{
1919
/// 1. It is an async function (or a function/closure that returns an appropriate future);
2020
/// 1. The function parameters (up to 12) implement [`FromRequest`];
2121
/// 1. The async function (or future) resolves to a type that can be converted into an
22-
/// [`HttpResponse`] (i.e., it implements the [`Responder`] trait).
22+
/// [`HttpResponse`] (i.e., it implements the [`Responder`] trait).
2323
///
2424
///
2525
/// # Compiler Errors

actix-web/src/http/header/content_disposition.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ impl Header for ContentDisposition {
493493
}
494494

495495
fn parse<T: crate::HttpMessage>(msg: &T) -> Result<Self, crate::error::ParseError> {
496-
if let Some(h) = msg.headers().get(&Self::name()) {
496+
if let Some(h) = msg.headers().get(Self::name()) {
497497
Self::from_raw(h)
498498
} else {
499499
Err(crate::error::ParseError::Header)

actix-web/src/http/header/range.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ impl ByteRangeSpec {
107107
/// satisfiable if they meet the following conditions:
108108
///
109109
/// > If a valid byte-range-set includes at least one byte-range-spec with a first-byte-pos that
110-
/// is less than the current length of the representation, or at least one
111-
/// suffix-byte-range-spec with a non-zero suffix-length, then the byte-range-set
112-
/// is satisfiable. Otherwise, the byte-range-set is unsatisfiable.
110+
/// > is less than the current length of the representation, or at least one
111+
/// > suffix-byte-range-spec with a non-zero suffix-length, then the byte-range-set is
112+
/// > satisfiable. Otherwise, the byte-range-set is unsatisfiable.
113113
///
114114
/// The function also computes remainder ranges based on the RFC:
115115
///
116116
/// > If the last-byte-pos value is absent, or if the value is greater than or equal to the
117-
/// current length of the representation data, the byte range is interpreted as the remainder
118-
/// of the representation (i.e., the server replaces the value of last-byte-pos with a value
119-
/// that is one less than the current length of the selected representation).
117+
/// > current length of the representation data, the byte range is interpreted as the remainder
118+
/// > of the representation (i.e., the server replaces the value of last-byte-pos with a value
119+
/// > that is one less than the current length of the selected representation).
120120
///
121121
/// [RFC 7233 §2.1]: https://datatracker.ietf.org/doc/html/rfc7233
122122
pub fn to_satisfiable_range(&self, full_length: u64) -> Option<(u64, u64)> {
@@ -270,7 +270,7 @@ impl Header for Range {
270270

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

actix-web/src/middleware/logger.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,7 @@ impl FormatText {
622622

623623
FormatText::ResponseHeader(ref name) => {
624624
let s = if let Some(val) = res.headers().get(name) {
625-
if let Ok(s) = val.to_str() {
626-
s
627-
} else {
628-
"-"
629-
}
625+
val.to_str().unwrap_or("-")
630626
} else {
631627
"-"
632628
};
@@ -670,11 +666,7 @@ impl FormatText {
670666
FormatText::RequestTime => *self = FormatText::Str(now.format(&Rfc3339).unwrap()),
671667
FormatText::RequestHeader(ref name) => {
672668
let s = if let Some(val) = req.headers().get(name) {
673-
if let Ok(s) = val.to_str() {
674-
s
675-
} else {
676-
"-"
677-
}
669+
val.to_str().unwrap_or("-")
678670
} else {
679671
"-"
680672
};

actix-web/src/response/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ mod tests {
463463
// content type override
464464
let res = HttpResponse::Ok()
465465
.insert_header((CONTENT_TYPE, "text/json"))
466-
.json(&vec!["v1", "v2", "v3"]);
466+
.json(["v1", "v2", "v3"]);
467467
let ct = res.headers().get(CONTENT_TYPE).unwrap();
468468
assert_eq!(ct, HeaderValue::from_static("text/json"));
469469
assert_body_eq!(res, br#"["v1","v2","v3"]"#);

0 commit comments

Comments
 (0)