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

updated Connector docs and renamed service() to finish() (#757)

* added Connector to actix-web::client namespace

* updated Connector, renaming service() to finish() and adding docs

* added doc for finish method on Connector
This commit is contained in:
Darin 2019-04-05 14:34:27 -04:00 committed by Nikolay Kim
parent b6dacaa23a
commit 18593d8476
4 changed files with 20 additions and 9 deletions

View File

@ -21,8 +21,18 @@ use openssl::ssl::SslConnector;
#[cfg(not(feature = "ssl"))] #[cfg(not(feature = "ssl"))]
type SslConnector = (); type SslConnector = ();
/// Http client connector builde instance. /// Manages http client network connectivity
/// `Connector` type uses builder-like pattern for connector service construction. /// The `Connector` type uses a builder-like combinator pattern for service
/// construction that finishes by calling the `.finish()` method.
///
/// ```rust
/// use actix-web::client::Connector;
/// use time::Duration;
///
/// let connector = Connector::new()
/// .timeout(Duration::from_secs(5))
/// .finish();
/// ```
pub struct Connector<T, U> { pub struct Connector<T, U> {
connector: T, connector: T,
timeout: Duration, timeout: Duration,
@ -164,7 +174,9 @@ where
} }
/// Finish configuration process and create connector service. /// Finish configuration process and create connector service.
pub fn service( /// The Connector builder always concludes by calling `finish()` last in
/// its combinator chain.
pub fn finish(
self, self,
) -> impl Service<Request = Uri, Response = impl Connection, Error = ConnectError> + Clone ) -> impl Service<Request = Uri, Response = impl Connection, Error = ConnectError> + Clone
{ {

View File

@ -31,7 +31,7 @@ impl ClientBuilder {
headers: HeaderMap::new(), headers: HeaderMap::new(),
timeout: Some(Duration::from_secs(5)), timeout: Some(Duration::from_secs(5)),
connector: RefCell::new(Box::new(ConnectorWrapper( connector: RefCell::new(Box::new(ConnectorWrapper(
Connector::new().service(), Connector::new().finish(),
))), ))),
}, },
} }

View File

@ -78,7 +78,7 @@ impl Default for Client {
fn default() -> Self { fn default() -> Self {
Client(Rc::new(ClientConfig { Client(Rc::new(ClientConfig {
connector: RefCell::new(Box::new(ConnectorWrapper( connector: RefCell::new(Box::new(ConnectorWrapper(
Connector::new().service(), Connector::new().finish(),
))), ))),
headers: HeaderMap::new(), headers: HeaderMap::new(),
timeout: Some(Duration::from_secs(5)), timeout: Some(Duration::from_secs(5)),

View File

@ -189,7 +189,6 @@ pub mod client {
pub use awc::error::{ pub use awc::error::{
ConnectError, InvalidUrl, PayloadError, SendRequestError, WsClientError, ConnectError, InvalidUrl, PayloadError, SendRequestError, WsClientError,
}; };
pub use awc::{ pub use awc::{test, Client, ClientBuilder, ClientRequest, ClientResponse,
test, Client, ClientBuilder, ClientRequest, ClientResponse, Connector, Connector};
};
} }