diff --git a/actix-identity/src/lib.rs b/actix-identity/src/lib.rs index 8ec4325ff..c3c632c7c 100644 --- a/actix-identity/src/lib.rs +++ b/actix-identity/src/lib.rs @@ -46,6 +46,9 @@ //! .service(web::resource("/logout.html").to(logout)); //! } //! ``` + +#![allow(clippy::needless_doctest_main)] + use std::cell::RefCell; use std::future::Future; use std::rc::Rc; @@ -200,14 +203,12 @@ pub trait IdentityPolicy: Sized + 'static { /// use actix_web::App; /// use actix_identity::{CookieIdentityPolicy, IdentityService}; /// -/// fn main() { -/// let app = App::new().wrap(IdentityService::new( -/// // <- create identity middleware -/// CookieIdentityPolicy::new(&[0; 32]) // <- create cookie session backend -/// .name("auth-cookie") -/// .secure(false), -/// )); -/// } +/// let app = App::new().wrap(IdentityService::new( +/// // <- create identity middleware +/// CookieIdentityPolicy::new(&[0; 32]) // <- create cookie session backend +/// .name("auth-cookie") +/// .secure(false), +/// )); /// ``` pub struct IdentityService { backend: Rc, @@ -427,16 +428,12 @@ impl CookieIdentityInner { let value: CookieValue = serde_json::from_str(cookie.value()).ok()?; let now = SystemTime::now(); if let Some(visit_deadline) = self.visit_deadline { - if now.duration_since(value.visit_timestamp?).ok()? - > visit_deadline - { + if now.duration_since(value.visit_timestamp?).ok()? > visit_deadline { return None; } } if let Some(login_deadline) = self.login_deadline { - if now.duration_since(value.login_timestamp?).ok()? - > login_deadline - { + if now.duration_since(value.login_timestamp?).ok()? > login_deadline { return None; } } @@ -469,16 +466,14 @@ impl CookieIdentityInner { /// use actix_web::App; /// use actix_identity::{CookieIdentityPolicy, IdentityService}; /// -/// fn main() { -/// let app = App::new().wrap(IdentityService::new( -/// // <- create identity middleware -/// CookieIdentityPolicy::new(&[0; 32]) // <- construct cookie policy -/// .domain("www.rust-lang.org") -/// .name("actix_auth") -/// .path("/") -/// .secure(true), -/// )); -/// } +/// let app = App::new().wrap(IdentityService::new( +/// // <- create identity middleware +/// CookieIdentityPolicy::new(&[0; 32]) // <- construct cookie policy +/// .domain("www.rust-lang.org") +/// .name("actix_auth") +/// .path("/") +/// .secure(true), +/// )); /// ``` pub struct CookieIdentityPolicy(Rc); @@ -557,11 +552,7 @@ impl IdentityPolicy for CookieIdentityPolicy { fn from_request(&self, req: &mut ServiceRequest) -> Self::Future { ok(self.0.load(req).map( - |CookieValue { - identity, - login_timestamp, - .. - }| { + |CookieValue { identity, login_timestamp, .. }| { if self.0.requires_oob_data() { req.extensions_mut() .insert(CookieIdentityExtention { login_timestamp }); @@ -761,14 +752,12 @@ mod tests { ) .secure(false) .name(COOKIE_NAME)))) - .service(web::resource("/").to(|id: Identity| { - async move { - let identity = id.identity(); - if identity.is_none() { - id.remember(COOKIE_LOGIN.to_string()) - } - web::Json(identity) + .service(web::resource("/").to(|id: Identity| async move { + let identity = id.identity(); + if identity.is_none() { + id.remember(COOKIE_LOGIN.to_string()) } + web::Json(identity) })), ) .await @@ -822,12 +811,14 @@ mod tests { assert_eq!(cookie.value(), identity); } + #[allow(clippy::enum_variant_names)] enum LoginTimestampCheck { NoTimestamp, NewTimestamp, OldTimestamp(SystemTime), } + #[allow(clippy::enum_variant_names)] enum VisitTimeStampCheck { NoTimestamp, NewTimestamp, @@ -1108,12 +1099,12 @@ mod tests { let mut srv = IdentityServiceMiddleware { backend: Rc::new(Ident), - service: Rc::new(RefCell::new(into_service(|_: ServiceRequest| { - async move { + service: Rc::new(RefCell::new(into_service( + |_: ServiceRequest| async move { actix_rt::time::delay_for(std::time::Duration::from_secs(100)).await; Err::(error::ErrorBadRequest("error")) - } - }))), + }, + ))), }; let mut srv2 = srv.clone(); diff --git a/actix-protobuf/src/lib.rs b/actix-protobuf/src/lib.rs index d4b3d0ff5..a8f39c6a5 100644 --- a/actix-protobuf/src/lib.rs +++ b/actix-protobuf/src/lib.rs @@ -144,10 +144,10 @@ impl Responder for ProtoBuf { self.0 .encode(&mut buf) .map_err(|e| Error::from(ProtoBufPayloadError::Serialize(e))) - .and_then(|()| { - Ok(HttpResponse::Ok() + .map(|()| { + HttpResponse::Ok() .content_type("application/protobuf") - .body(buf)) + .body(buf) }), ) } diff --git a/actix-session/src/cookie.rs b/actix-session/src/cookie.rs index 880ce3bf9..94c27bcee 100644 --- a/actix-session/src/cookie.rs +++ b/actix-session/src/cookie.rs @@ -203,15 +203,13 @@ impl CookieSessionInner { /// use actix_session::CookieSession; /// use actix_web::{web, App, HttpResponse, HttpServer}; /// -/// fn main() { -/// let app = App::new().wrap( -/// CookieSession::signed(&[0; 32]) -/// .domain("www.rust-lang.org") -/// .name("actix_session") -/// .path("/") -/// .secure(true)) -/// .service(web::resource("/").to(|| HttpResponse::Ok())); -/// } +/// let app = App::new().wrap( +/// CookieSession::signed(&[0; 32]) +/// .domain("www.rust-lang.org") +/// .name("actix_session") +/// .path("/") +/// .secure(true)) +/// .service(web::resource("/").to(|| HttpResponse::Ok())); /// ``` pub struct CookieSession(Rc); @@ -256,7 +254,7 @@ impl CookieSession { /// When true, prevents adding session cookies to responses until /// the session contains data. Default is `false`. - /// + /// /// Useful when trying to comply with laws that require consent for setting cookies. pub fn lazy(mut self, value: bool) -> CookieSession { Rc::get_mut(&mut self.0).unwrap().lazy = value; @@ -451,18 +449,13 @@ mod tests { let _ = ses.set("counter", 100); "counting" })) - .service(web::resource("/").to(|_ses: Session| async move { - "test" - })), + .service(web::resource("/").to(|_ses: Session| async move { "test" })), ) .await; let request = test::TestRequest::get().to_request(); let response = app.call(request).await.unwrap(); - assert!(response - .response() - .cookies() - .count() == 0); + assert!(response.response().cookies().count() == 0); let request = test::TestRequest::with_uri("/count").to_request(); let response = app.call(request).await.unwrap(); diff --git a/actix-session/src/lib.rs b/actix-session/src/lib.rs index ed79a2809..d363a955c 100644 --- a/actix-session/src/lib.rs +++ b/actix-session/src/lib.rs @@ -276,7 +276,8 @@ mod tests { let mut req = test::TestRequest::default().to_srv_request(); Session::set_session( - vec![("key".to_string(), serde_json::to_string("value").unwrap())].into_iter(), + vec![("key".to_string(), serde_json::to_string("value").unwrap())] + .into_iter(), &mut req, ); let session = Session::get_session(&mut *req.extensions_mut());