feat(lib): add optional tcp feature, split from runtime
The `HttpConnector` and `AddrListener` types which make use of `tokio::tcp` have been made their own optional feature. This allows using them without requiring the *full* tokio runtime.
This commit is contained in:
@@ -249,15 +249,18 @@ impl Iterator for IpAddrs {
|
||||
///
|
||||
/// Unlike the `GaiResolver` this will not spawn dedicated threads, but only works when running on the
|
||||
/// multi-threaded Tokio runtime.
|
||||
#[cfg(feature = "runtime")]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TokioThreadpoolGaiResolver(());
|
||||
|
||||
/// The future returned by `TokioThreadpoolGaiResolver`.
|
||||
#[cfg(feature = "runtime")]
|
||||
#[derive(Debug)]
|
||||
pub struct TokioThreadpoolGaiFuture {
|
||||
name: Name,
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime")]
|
||||
impl TokioThreadpoolGaiResolver {
|
||||
/// Creates a new DNS resolver that will use tokio threadpool's blocking
|
||||
/// feature.
|
||||
@@ -268,6 +271,7 @@ impl TokioThreadpoolGaiResolver {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime")]
|
||||
impl Resolve for TokioThreadpoolGaiResolver {
|
||||
type Addrs = GaiAddrs;
|
||||
type Future = TokioThreadpoolGaiFuture;
|
||||
@@ -277,6 +281,7 @@ impl Resolve for TokioThreadpoolGaiResolver {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime")]
|
||||
impl Future for TokioThreadpoolGaiFuture {
|
||||
type Output = Result<GaiAddrs, io::Error>;
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ use tokio_timer::Delay;
|
||||
|
||||
use crate::common::{Future, Pin, Poll, task};
|
||||
use super::{Connect, Connected, Destination};
|
||||
use super::dns::{self, GaiResolver, Resolve, TokioThreadpoolGaiResolver};
|
||||
use super::dns::{self, GaiResolver, Resolve};
|
||||
#[cfg(feature = "runtime")] use super::dns::TokioThreadpoolGaiResolver;
|
||||
|
||||
// TODO: unbox me?
|
||||
type ConnectFuture = Pin<Box<dyn Future<Output = io::Result<TcpStream>> + Send>>;
|
||||
@@ -81,6 +82,7 @@ impl HttpConnector {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime")]
|
||||
impl HttpConnector<TokioThreadpoolGaiResolver> {
|
||||
/// Construct a new HttpConnector using the `TokioThreadpoolGaiResolver`.
|
||||
///
|
||||
|
||||
@@ -15,9 +15,9 @@ use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::common::{Future, Unpin};
|
||||
|
||||
#[cfg(feature = "runtime")] pub mod dns;
|
||||
#[cfg(feature = "runtime")] mod http;
|
||||
#[cfg(feature = "runtime")] pub use self::http::{HttpConnector, HttpInfo};
|
||||
#[cfg(feature = "tcp")] pub mod dns;
|
||||
#[cfg(feature = "tcp")] mod http;
|
||||
#[cfg(feature = "tcp")] pub use self::http::{HttpConnector, HttpInfo};
|
||||
|
||||
/// Connect to a destination, returning an IO transport.
|
||||
///
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
//! ```
|
||||
//! use hyper::{Client, Uri};
|
||||
//!
|
||||
//! # #[cfg(feature = "runtime")]
|
||||
//! # #[cfg(feature = "tcp")]
|
||||
//! # async fn fetch_httpbin() -> hyper::Result<()> {
|
||||
//! let client = Client::new();
|
||||
//!
|
||||
@@ -75,7 +75,7 @@ use crate::common::{lazy as hyper_lazy, Lazy, Future, Pin, Poll, task};
|
||||
use self::connect::{Alpn, Connect, Connected, Destination};
|
||||
use self::pool::{Key as PoolKey, Pool, Poolable, Pooled, Reservation};
|
||||
|
||||
#[cfg(feature = "runtime")] pub use self::connect::HttpConnector;
|
||||
#[cfg(feature = "tcp")] pub use self::connect::HttpConnector;
|
||||
|
||||
pub mod conn;
|
||||
pub mod connect;
|
||||
@@ -110,7 +110,7 @@ pub struct ResponseFuture {
|
||||
|
||||
// ===== impl Client =====
|
||||
|
||||
#[cfg(feature = "runtime")]
|
||||
#[cfg(feature = "tcp")]
|
||||
impl Client<HttpConnector, Body> {
|
||||
/// Create a new Client with the default [config](Builder).
|
||||
///
|
||||
@@ -125,7 +125,7 @@ impl Client<HttpConnector, Body> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "runtime")]
|
||||
#[cfg(feature = "tcp")]
|
||||
impl Default for Client<HttpConnector, Body> {
|
||||
fn default() -> Client<HttpConnector, Body> {
|
||||
Client::new()
|
||||
@@ -1018,7 +1018,7 @@ impl Builder {
|
||||
}
|
||||
|
||||
/// Builder a client with this configuration and the default `HttpConnector`.
|
||||
#[cfg(feature = "runtime")]
|
||||
#[cfg(feature = "tcp")]
|
||||
pub fn build_http<B>(&self) -> Client<HttpConnector, B>
|
||||
where
|
||||
B: Payload + Send,
|
||||
|
||||
Reference in New Issue
Block a user