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

This commit is contained in:
dowwie 2019-04-05 14:22:07 -04:00
parent 79bbe5d35c
commit 275cef728f
3 changed files with 15 additions and 5 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,7 @@ where
} }
/// Finish configuration process and create connector service. /// Finish configuration process and create connector service.
pub fn service( 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)),