diff --git a/src/app.rs b/src/app.rs index 8c4168085..c4f2e33bd 100644 --- a/src/app.rs +++ b/src/app.rs @@ -148,7 +148,7 @@ where } /// Register a request modifier. It can modify any request parameters - /// including payload stream. + /// including payload stream type. pub fn chain( self, chain: C, @@ -211,6 +211,14 @@ where } /// Register http service. + /// + /// Http service is any type that implements `HttpServiceFactory` trait. + /// + /// Actix web provides several services implementations: + /// + /// * *Resource* is an entry in resource table which corresponds to requested URL. + /// * *Scope* is a set of resources with common root path. + /// * "StaticFiles" is a service for static files support pub fn service(self, service: F) -> AppRouter> where F: HttpServiceFactory

+ 'static, @@ -301,7 +309,7 @@ where /// /// Actix web provides several services implementations: /// - /// * *Resource* is an entry in route table which corresponds to requested URL. + /// * *Resource* is an entry in resource table which corresponds to requested URL. /// * *Scope* is a set of resources with common root path. /// * "StaticFiles" is a service for static files support pub fn service(mut self, factory: F) -> Self @@ -354,9 +362,6 @@ where } /// Default resource to be used if no matching route could be found. - /// - /// Default resource works with resources only and does not work with - /// custom services. pub fn default_resource(mut self, f: F) -> Self where F: FnOnce(Resource

) -> Resource, diff --git a/src/info.rs b/src/info.rs index c058bd517..9a97c3353 100644 --- a/src/info.rs +++ b/src/info.rs @@ -25,7 +25,7 @@ impl ConnectionInfo { Ref::map(req.extensions(), |e| e.get().unwrap()) } - #[cfg_attr(feature = "cargo-clippy", allow(cyclomatic_complexity))] + #[allow(clippy::cyclomatic_complexity)] fn new(req: &RequestHead, cfg: &AppConfig) -> ConnectionInfo { let mut host = None; let mut scheme = None; @@ -123,10 +123,10 @@ impl ConnectionInfo { } ConnectionInfo { + peer, scheme: scheme.unwrap_or("http").to_owned(), host: host.unwrap_or("localhost").to_owned(), remote: remote.map(|s| s.to_owned()), - peer: peer, } } diff --git a/src/lib.rs b/src/lib.rs index b22e05da0..509fcc608 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![allow(clippy::type_complexity)] +#![allow(clippy::type_complexity, clippy::new_without_default)] mod app; mod app_service; @@ -84,6 +84,7 @@ pub mod web { pub use actix_http::Response as HttpResponse; pub use bytes::{Bytes, BytesMut}; + use crate::error::{BlockingError, Error}; use crate::extract::FromRequest; use crate::handler::{AsyncFactory, Factory}; use crate::resource::Resource; @@ -92,7 +93,6 @@ pub mod web { use crate::scope::Scope; pub use crate::data::{Data, RouteData}; - pub use crate::error::{BlockingError, Error}; pub use crate::extract::{Form, Json, Path, Payload, Query}; pub use crate::extract::{FormConfig, JsonConfig, PayloadConfig}; pub use crate::request::HttpRequest; diff --git a/src/resource.rs b/src/resource.rs index e4fe65c05..46b3e2a8f 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -21,7 +21,7 @@ type HttpService

= BoxedService, ServiceResponse, Error>; type HttpNewService

= BoxedNewService<(), ServiceRequest

, ServiceResponse, Error, ()>; -/// *Resource* is an entry in route table which corresponds to requested URL. +/// *Resource* is an entry in resources table which corresponds to requested URL. /// /// Resource in turn has at least one route. /// Route consists of an handlers objects and list of guards @@ -132,7 +132,8 @@ where /// } /// ``` /// - /// Multiple routes could be added to a resource. + /// Multiple routes could be added to a resource. Resource object uses + /// match guards for route selection. /// /// ```rust /// use actix_web::{web, guard, App, HttpResponse}; @@ -220,11 +221,11 @@ where self } - /// Register a resource middleware + /// Register a resource middleware. /// - /// This is similar to `App's` middlewares, but - /// middleware is not allowed to change response type (i.e modify response's body). - /// Middleware get invoked on resource level. + /// This is similar to `App's` middlewares, but middleware get invoked on resource level. + /// Resource level middlewares are not allowed to change response + /// type (i.e modify response's body). pub fn middleware( self, mw: F, diff --git a/src/route.rs b/src/route.rs index c44ed713f..626b09514 100644 --- a/src/route.rs +++ b/src/route.rs @@ -62,7 +62,7 @@ impl Route

{ } pub(crate) fn finish(mut self) -> Self { - *self.data_ref.borrow_mut() = self.data.take().map(|e| Rc::new(e)); + *self.data_ref.borrow_mut() = self.data.take().map(Rc::new); self } diff --git a/src/scope.rs b/src/scope.rs index 9f5b650cd..bf3261f2f 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -26,7 +26,7 @@ type HttpNewService

= BoxedNewService<(), ServiceRequest

, ServiceResponse, Error, ()>; type BoxedResponse = Box>; -/// Resources scope +/// Resources scope. /// /// Scope is a set of resources with common root path. /// Scopes collect multiple paths under a common path prefix. @@ -114,7 +114,15 @@ where self } - /// Create nested service. + /// Register http service. + /// + /// This is similar to `App's` service registration. + /// + /// Actix web provides several services implementations: + /// + /// * *Resource* is an entry in resource table which corresponds to requested URL. + /// * *Scope* is a set of resources with common root path. + /// * "StaticFiles" is a service for static files support /// /// ```rust /// use actix_web::{web, App, HttpRequest}; @@ -145,7 +153,7 @@ where /// Configure route for a specific path. /// /// This is a simplified version of the `Scope::service()` method. - /// This method can not be could multiple times, in that case + /// This method can be called multiple times, in that case /// multiple resources with one route would be registered for same resource path. /// /// ```rust @@ -172,6 +180,8 @@ where } /// Default resource to be used if no matching route could be found. + /// + /// If default resource is not registered, app's default resource is being used. pub fn default_resource(mut self, f: F) -> Self where F: FnOnce(Resource

) -> Resource, @@ -190,11 +200,11 @@ where self } - /// Register a scope middleware + /// Register a scope level middleware. /// - /// This is similar to `App's` middlewares, but - /// middleware is not allowed to change response type (i.e modify response's body). - /// Middleware get invoked on scope level. + /// This is similar to `App's` middlewares, but middleware get invoked on scope level. + /// Scope level middlewares are not allowed to change response + /// type (i.e modify response's body). pub fn middleware( self, mw: F, @@ -322,7 +332,7 @@ impl NewService for ScopeFactory

{ } } -/// Create app service +/// Create scope service #[doc(hidden)] pub struct ScopeFactoryResponse

{ fut: Vec>, diff --git a/src/test.rs b/src/test.rs index 4db268f14..13db59771 100644 --- a/src/test.rs +++ b/src/test.rs @@ -50,7 +50,7 @@ pub fn run_on(f: F) -> Result where F: Fn() -> Result, { - RT.with(move |rt| rt.borrow_mut().block_on(lazy(|| f()))) + RT.with(move |rt| rt.borrow_mut().block_on(lazy(f))) } /// This method accepts application builder instance, and constructs @@ -169,6 +169,7 @@ impl Default for TestRequest { } } +#[allow(clippy::wrong_self_convention)] impl TestRequest { /// Create TestRequest and set request uri pub fn with_uri(path: &str) -> TestRequest { @@ -254,7 +255,7 @@ impl TestRequest { } /// Set cookie for this request - pub fn cookie<'a>(mut self, cookie: Cookie<'a>) -> Self { + pub fn cookie(mut self, cookie: Cookie) -> Self { self.req.cookie(cookie); self }