1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-30 18:44:35 +01:00

cleanup doc strings and clippy warnings

This commit is contained in:
Nikolay Kim 2019-03-16 21:35:02 -07:00
parent e396c90c9e
commit 4a4826b23a
7 changed files with 43 additions and 26 deletions

View File

@ -148,7 +148,7 @@ where
} }
/// Register a request modifier. It can modify any request parameters /// Register a request modifier. It can modify any request parameters
/// including payload stream. /// including payload stream type.
pub fn chain<C, F, P1>( pub fn chain<C, F, P1>(
self, self,
chain: C, chain: C,
@ -211,6 +211,14 @@ where
} }
/// Register http service. /// 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<F>(self, service: F) -> AppRouter<T, P, Body, AppEntry<P>> pub fn service<F>(self, service: F) -> AppRouter<T, P, Body, AppEntry<P>>
where where
F: HttpServiceFactory<P> + 'static, F: HttpServiceFactory<P> + 'static,
@ -301,7 +309,7 @@ where
/// ///
/// Actix web provides several services implementations: /// 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. /// * *Scope* is a set of resources with common root path.
/// * "StaticFiles" is a service for static files support /// * "StaticFiles" is a service for static files support
pub fn service<F>(mut self, factory: F) -> Self pub fn service<F>(mut self, factory: F) -> Self
@ -354,9 +362,6 @@ where
} }
/// Default resource to be used if no matching route could be found. /// 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<F, U>(mut self, f: F) -> Self pub fn default_resource<F, U>(mut self, f: F) -> Self
where where
F: FnOnce(Resource<P>) -> Resource<P, U>, F: FnOnce(Resource<P>) -> Resource<P, U>,

View File

@ -25,7 +25,7 @@ impl ConnectionInfo {
Ref::map(req.extensions(), |e| e.get().unwrap()) 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 { fn new(req: &RequestHead, cfg: &AppConfig) -> ConnectionInfo {
let mut host = None; let mut host = None;
let mut scheme = None; let mut scheme = None;
@ -123,10 +123,10 @@ impl ConnectionInfo {
} }
ConnectionInfo { ConnectionInfo {
peer,
scheme: scheme.unwrap_or("http").to_owned(), scheme: scheme.unwrap_or("http").to_owned(),
host: host.unwrap_or("localhost").to_owned(), host: host.unwrap_or("localhost").to_owned(),
remote: remote.map(|s| s.to_owned()), remote: remote.map(|s| s.to_owned()),
peer: peer,
} }
} }

View File

@ -1,4 +1,4 @@
#![allow(clippy::type_complexity)] #![allow(clippy::type_complexity, clippy::new_without_default)]
mod app; mod app;
mod app_service; mod app_service;
@ -84,6 +84,7 @@ pub mod web {
pub use actix_http::Response as HttpResponse; pub use actix_http::Response as HttpResponse;
pub use bytes::{Bytes, BytesMut}; pub use bytes::{Bytes, BytesMut};
use crate::error::{BlockingError, Error};
use crate::extract::FromRequest; use crate::extract::FromRequest;
use crate::handler::{AsyncFactory, Factory}; use crate::handler::{AsyncFactory, Factory};
use crate::resource::Resource; use crate::resource::Resource;
@ -92,7 +93,6 @@ pub mod web {
use crate::scope::Scope; use crate::scope::Scope;
pub use crate::data::{Data, RouteData}; 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::{Form, Json, Path, Payload, Query};
pub use crate::extract::{FormConfig, JsonConfig, PayloadConfig}; pub use crate::extract::{FormConfig, JsonConfig, PayloadConfig};
pub use crate::request::HttpRequest; pub use crate::request::HttpRequest;

View File

@ -21,7 +21,7 @@ type HttpService<P> = BoxedService<ServiceRequest<P>, ServiceResponse, Error>;
type HttpNewService<P> = type HttpNewService<P> =
BoxedNewService<(), ServiceRequest<P>, ServiceResponse, Error, ()>; BoxedNewService<(), ServiceRequest<P>, 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. /// Resource in turn has at least one route.
/// Route consists of an handlers objects and list of guards /// 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 /// ```rust
/// use actix_web::{web, guard, App, HttpResponse}; /// use actix_web::{web, guard, App, HttpResponse};
@ -220,11 +221,11 @@ where
self self
} }
/// Register a resource middleware /// Register a resource middleware.
/// ///
/// This is similar to `App's` middlewares, but /// This is similar to `App's` middlewares, but middleware get invoked on resource level.
/// middleware is not allowed to change response type (i.e modify response's body). /// Resource level middlewares are not allowed to change response
/// Middleware get invoked on resource level. /// type (i.e modify response's body).
pub fn middleware<M, F>( pub fn middleware<M, F>(
self, self,
mw: F, mw: F,

View File

@ -62,7 +62,7 @@ impl<P: 'static> Route<P> {
} }
pub(crate) fn finish(mut self) -> Self { 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 self
} }

View File

@ -26,7 +26,7 @@ type HttpNewService<P> =
BoxedNewService<(), ServiceRequest<P>, ServiceResponse, Error, ()>; BoxedNewService<(), ServiceRequest<P>, ServiceResponse, Error, ()>;
type BoxedResponse = Box<Future<Item = ServiceResponse, Error = Error>>; type BoxedResponse = Box<Future<Item = ServiceResponse, Error = Error>>;
/// Resources scope /// Resources scope.
/// ///
/// Scope is a set of resources with common root path. /// Scope is a set of resources with common root path.
/// Scopes collect multiple paths under a common path prefix. /// Scopes collect multiple paths under a common path prefix.
@ -114,7 +114,15 @@ where
self 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 /// ```rust
/// use actix_web::{web, App, HttpRequest}; /// use actix_web::{web, App, HttpRequest};
@ -145,7 +153,7 @@ where
/// Configure route for a specific path. /// Configure route for a specific path.
/// ///
/// This is a simplified version of the `Scope::service()` method. /// 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. /// multiple resources with one route would be registered for same resource path.
/// ///
/// ```rust /// ```rust
@ -172,6 +180,8 @@ where
} }
/// Default resource to be used if no matching route could be found. /// 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<F, U>(mut self, f: F) -> Self pub fn default_resource<F, U>(mut self, f: F) -> Self
where where
F: FnOnce(Resource<P>) -> Resource<P, U>, F: FnOnce(Resource<P>) -> Resource<P, U>,
@ -190,11 +200,11 @@ where
self self
} }
/// Register a scope middleware /// Register a scope level middleware.
/// ///
/// This is similar to `App's` middlewares, but /// This is similar to `App's` middlewares, but middleware get invoked on scope level.
/// middleware is not allowed to change response type (i.e modify response's body). /// Scope level middlewares are not allowed to change response
/// Middleware get invoked on scope level. /// type (i.e modify response's body).
pub fn middleware<M, F>( pub fn middleware<M, F>(
self, self,
mw: F, mw: F,
@ -322,7 +332,7 @@ impl<P: 'static> NewService for ScopeFactory<P> {
} }
} }
/// Create app service /// Create scope service
#[doc(hidden)] #[doc(hidden)]
pub struct ScopeFactoryResponse<P> { pub struct ScopeFactoryResponse<P> {
fut: Vec<CreateScopeServiceItem<P>>, fut: Vec<CreateScopeServiceItem<P>>,

View File

@ -50,7 +50,7 @@ pub fn run_on<F, I, E>(f: F) -> Result<I, E>
where where
F: Fn() -> Result<I, E>, F: Fn() -> Result<I, E>,
{ {
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 /// This method accepts application builder instance, and constructs
@ -169,6 +169,7 @@ impl Default for TestRequest {
} }
} }
#[allow(clippy::wrong_self_convention)]
impl TestRequest { impl TestRequest {
/// Create TestRequest and set request uri /// Create TestRequest and set request uri
pub fn with_uri(path: &str) -> TestRequest { pub fn with_uri(path: &str) -> TestRequest {
@ -254,7 +255,7 @@ impl TestRequest {
} }
/// Set cookie for this request /// 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.req.cookie(cookie);
self self
} }