1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-30 17:44:34 +01:00

update docs

This commit is contained in:
Nikolay Kim 2019-12-10 21:34:51 +06:00
parent d29e7c4ba6
commit bf734a31dc
5 changed files with 22 additions and 19 deletions

View File

@ -30,14 +30,16 @@ fn main() -> io::Result<()> {
let num = num.clone(); let num = num.clone();
let acceptor = acceptor.clone(); let acceptor = acceptor.clone();
// construct transformation pipeline
pipeline(
// service for converting incoming TcpStream to a SslStream<TcpStream> // service for converting incoming TcpStream to a SslStream<TcpStream>
fn_service(move |stream: Io<tokio_tcp::TcpStream>| { fn_service(move |stream: actix_rt::net::TcpStream| async move {
SslAcceptorExt::accept_async(&acceptor, stream.into_parts().0) SslAcceptorExt::accept_async(&acceptor, stream.into_parts().0).await
.map_err(|e| println!("Openssl error: {}", e)) .map_err(|e| println!("Openssl error: {}", e))
}) }))
// .and_then() combinator uses other service to convert incoming `Request` to a // .and_then() combinator chains result of previos service call to argument
// `Response` and then uses that response as an input for next /// for next service calll. in this case, on success we chain
// service. in this case, on success we use `logger` service /// ssl stream to the `logger` service.
.and_then(fn_service(logger)) .and_then(fn_service(logger))
// Next service counts number of connections // Next service counts number of connections
.and_then(move |_| { .and_then(move |_| {

View File

@ -5,7 +5,7 @@ use std::task::{Context, Poll};
use super::{IntoService, IntoServiceFactory, Service, ServiceFactory}; use super::{IntoService, IntoServiceFactory, Service, ServiceFactory};
/// Apply tranform function to a service /// Apply tranform function to a service.
pub fn apply_fn<T, F, R, In, Out, Err, U>(service: U, f: F) -> Apply<T, F, R, In, Out, Err> pub fn apply_fn<T, F, R, In, Out, Err, U>(service: U, f: F) -> Apply<T, F, R, In, Out, Err>
where where
T: Service<Error = Err>, T: Service<Error = Err>,
@ -16,7 +16,7 @@ where
Apply::new(service.into_service(), f) Apply::new(service.into_service(), f)
} }
/// Create factory for `apply` service. /// Service factory that prodices `apply_fn` service.
pub fn apply_fn_factory<T, F, R, In, Out, Err, U>( pub fn apply_fn_factory<T, F, R, In, Out, Err, U>(
service: U, service: U,
f: F, f: F,

View File

@ -6,7 +6,7 @@ use std::task::{Context, Poll};
use crate::cell::Cell; use crate::cell::Cell;
use crate::{Service, ServiceFactory}; use crate::{Service, ServiceFactory};
/// Convert `Fn(&Config, &mut Service) -> Future<Service>` fn to a NewService /// Convert `Fn(Config, &mut Service1) -> Future<Service2>` fn to a service factory
pub fn apply_cfg<F, C, T, R, S, E>(srv: T, f: F) -> ApplyConfigService<F, C, T, R, S, E> pub fn apply_cfg<F, C, T, R, S, E>(srv: T, f: F) -> ApplyConfigService<F, C, T, R, S, E>
where where
F: FnMut(C, &mut T) -> R, F: FnMut(C, &mut T) -> R,
@ -20,10 +20,11 @@ where
} }
} }
/// Convert `Fn(&Config, &mut Service) -> Future<Service>` fn to a NewService /// Convert `Fn(Config, &mut Service1) -> Future<Service2>` fn to a service factory
/// Service get constructor from NewService. ///
/// Service1 get constructed from `T` factory.
pub fn apply_cfg_factory<F, C, T, R, S>( pub fn apply_cfg_factory<F, C, T, R, S>(
srv: T, factory: T,
f: F, f: F,
) -> ApplyConfigServiceFactory<F, C, T, R, S> ) -> ApplyConfigServiceFactory<F, C, T, R, S>
where where
@ -34,12 +35,12 @@ where
S: Service, S: Service,
{ {
ApplyConfigServiceFactory { ApplyConfigServiceFactory {
srv: Cell::new((srv, f)), srv: Cell::new((factory, f)),
_t: PhantomData, _t: PhantomData,
} }
} }
/// Convert `Fn(&Config) -> Future<Service>` fn to NewService\ /// Convert `Fn(Config, &mut Server) -> Future<Service>` fn to NewService\
pub struct ApplyConfigService<F, C, T, R, S, E> pub struct ApplyConfigService<F, C, T, R, S, E>
where where
F: FnMut(C, &mut T) -> R, F: FnMut(C, &mut T) -> R,

View File

@ -13,7 +13,7 @@ pub type BoxService<Req, Res, Err> =
pub struct BoxServiceFactory<C, Req, Res, Err, InitErr>(Inner<C, Req, Res, Err, InitErr>); pub struct BoxServiceFactory<C, Req, Res, Err, InitErr>(Inner<C, Req, Res, Err, InitErr>);
/// Create boxed new service /// Create boxed service factory
pub fn factory<T>( pub fn factory<T>(
factory: T, factory: T,
) -> BoxServiceFactory<T::Config, T::Request, T::Response, T::Error, T::InitError> ) -> BoxServiceFactory<T::Config, T::Request, T::Response, T::Error, T::InitError>

View File

@ -31,7 +31,7 @@ where
} }
} }
/// Pipeline service /// Pipeline service - pipeline allows to compose multiple service into one service.
pub struct Pipeline<T> { pub struct Pipeline<T> {
service: T, service: T,
} }
@ -161,7 +161,7 @@ impl<T: Service> Service for Pipeline<T> {
} }
} }
/// Pipeline constructor /// Pipeline factory
pub struct PipelineFactory<T> { pub struct PipelineFactory<T> {
factory: T, factory: T,
} }