From bf734a31dc8b0a9e3aa1e7810aa90b8abf2588a3 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 10 Dec 2019 21:34:51 +0600 Subject: [PATCH] update docs --- README.md | 18 ++++++++++-------- actix-service/src/apply.rs | 4 ++-- actix-service/src/apply_cfg.rs | 13 +++++++------ actix-service/src/boxed.rs | 2 +- actix-service/src/pipeline.rs | 4 ++-- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 91ae2613..426cf6d6 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,16 @@ fn main() -> io::Result<()> { let num = num.clone(); let acceptor = acceptor.clone(); - // service for converting incoming TcpStream to a SslStream - fn_service(move |stream: Io| { - SslAcceptorExt::accept_async(&acceptor, stream.into_parts().0) - .map_err(|e| println!("Openssl error: {}", e)) - }) - // .and_then() combinator uses other service to convert incoming `Request` to a - // `Response` and then uses that response as an input for next - // service. in this case, on success we use `logger` service + // construct transformation pipeline + pipeline( + // service for converting incoming TcpStream to a SslStream + fn_service(move |stream: actix_rt::net::TcpStream| async move { + SslAcceptorExt::accept_async(&acceptor, stream.into_parts().0).await + .map_err(|e| println!("Openssl error: {}", e)) + })) + // .and_then() combinator chains result of previos service call to argument + /// for next service calll. in this case, on success we chain + /// ssl stream to the `logger` service. .and_then(fn_service(logger)) // Next service counts number of connections .and_then(move |_| { diff --git a/actix-service/src/apply.rs b/actix-service/src/apply.rs index c048fd15..b8cc7426 100644 --- a/actix-service/src/apply.rs +++ b/actix-service/src/apply.rs @@ -5,7 +5,7 @@ use std::task::{Context, Poll}; use super::{IntoService, IntoServiceFactory, Service, ServiceFactory}; -/// Apply tranform function to a service +/// Apply tranform function to a service. pub fn apply_fn(service: U, f: F) -> Apply where T: Service, @@ -16,7 +16,7 @@ where Apply::new(service.into_service(), f) } -/// Create factory for `apply` service. +/// Service factory that prodices `apply_fn` service. pub fn apply_fn_factory( service: U, f: F, diff --git a/actix-service/src/apply_cfg.rs b/actix-service/src/apply_cfg.rs index e6045321..a295639b 100644 --- a/actix-service/src/apply_cfg.rs +++ b/actix-service/src/apply_cfg.rs @@ -6,7 +6,7 @@ use std::task::{Context, Poll}; use crate::cell::Cell; use crate::{Service, ServiceFactory}; -/// Convert `Fn(&Config, &mut Service) -> Future` fn to a NewService +/// Convert `Fn(Config, &mut Service1) -> Future` fn to a service factory pub fn apply_cfg(srv: T, f: F) -> ApplyConfigService where F: FnMut(C, &mut T) -> R, @@ -20,10 +20,11 @@ where } } -/// Convert `Fn(&Config, &mut Service) -> Future` fn to a NewService -/// Service get constructor from NewService. +/// Convert `Fn(Config, &mut Service1) -> Future` fn to a service factory +/// +/// Service1 get constructed from `T` factory. pub fn apply_cfg_factory( - srv: T, + factory: T, f: F, ) -> ApplyConfigServiceFactory where @@ -34,12 +35,12 @@ where S: Service, { ApplyConfigServiceFactory { - srv: Cell::new((srv, f)), + srv: Cell::new((factory, f)), _t: PhantomData, } } -/// Convert `Fn(&Config) -> Future` fn to NewService\ +/// Convert `Fn(Config, &mut Server) -> Future` fn to NewService\ pub struct ApplyConfigService where F: FnMut(C, &mut T) -> R, diff --git a/actix-service/src/boxed.rs b/actix-service/src/boxed.rs index 8afc343c..e630f81c 100644 --- a/actix-service/src/boxed.rs +++ b/actix-service/src/boxed.rs @@ -13,7 +13,7 @@ pub type BoxService = pub struct BoxServiceFactory(Inner); -/// Create boxed new service +/// Create boxed service factory pub fn factory( factory: T, ) -> BoxServiceFactory diff --git a/actix-service/src/pipeline.rs b/actix-service/src/pipeline.rs index b101f837..d6107ce4 100644 --- a/actix-service/src/pipeline.rs +++ b/actix-service/src/pipeline.rs @@ -31,7 +31,7 @@ where } } -/// Pipeline service +/// Pipeline service - pipeline allows to compose multiple service into one service. pub struct Pipeline { service: T, } @@ -161,7 +161,7 @@ impl Service for Pipeline { } } -/// Pipeline constructor +/// Pipeline factory pub struct PipelineFactory { factory: T, }