diff options
author | Ferris Tseng <ferristseng@fastmail.fm> | 2021-02-08 23:17:45 -0500 |
---|---|---|
committer | Ferris Tseng <ferristseng@fastmail.fm> | 2021-02-08 23:17:45 -0500 |
commit | 129f884c511babbb41be3acfb247a075d1ba679f (patch) | |
tree | 472cb7e46524a7bd126072dd2047a5c37bc1930d /ipfs-api/src/lib.rs | |
parent | dfd40e2fbdca55dff6de64758bd8cbcec1f6e2bb (diff) |
cleaning up feature flag hell
Diffstat (limited to 'ipfs-api/src/lib.rs')
-rw-r--r-- | ipfs-api/src/lib.rs | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/ipfs-api/src/lib.rs b/ipfs-api/src/lib.rs index 9a5e1ca..27a3482 100644 --- a/ipfs-api/src/lib.rs +++ b/ipfs-api/src/lib.rs @@ -157,23 +157,19 @@ //! #[cfg(feature = "with-actix")] -extern crate actix_multipart_rfc7578 as actix_multipart; -#[cfg(feature = "with-actix")] #[macro_use] extern crate derive_more; #[cfg(feature = "with-hyper")] -extern crate hyper_multipart_rfc7578 as hyper_multipart; -#[cfg(feature = "with-hyper")] #[macro_use] extern crate failure; -extern crate serde; - #[cfg(feature = "with-builder")] #[macro_use] extern crate typed_builder; +extern crate serde; + pub use crate::client::{IpfsClient, TryFromUri}; pub use crate::request::{KeyType, Logger, LoggingLevel, ObjectTemplate}; @@ -183,36 +179,55 @@ mod read; pub mod request; pub mod response; -#[cfg(feature = "with-actix")] -use actix_http::{encoding, Payload, PayloadStream}; -#[cfg(feature = "with-hyper")] -use hyper::{self, client::HttpConnector}; -#[cfg(all(feature = "with-hyper-rustls", feature = "with-hyper-tls"))] -compile_error!("Pick only one of the features: hyper-tls, hyper-rustls"); +// --- Hyper Connectors --- + #[cfg(all(feature = "with-hyper-tls", not(feature = "with-hyper-rustls")))] -type HyperConnector = hyper_tls::HttpsConnector<HttpConnector>; +type HyperConnector = hyper_tls::HttpsConnector<hyper::client::HttpConnector>; #[cfg(all(feature = "with-hyper-rustls", not(feature = "with-hyper-tls")))] -type HyperConnector = hyper_rustls::HttpsConnector<HttpConnector>; -#[cfg(all(feature = "with-hyper", any( - not(any(feature = "with-hyper-tls", feature = "with-hyper-rustls")), - all(feature = "with-hyper-rustls", feature = "with-hyper-tls"), -)))] -type HyperConnector = HttpConnector; +type HyperConnector = hyper_rustls::HttpsConnector<hyper::client::HttpConnector>; +#[cfg(all( + feature = "with-hyper", + any( + not(any(feature = "with-hyper-tls", feature = "with-hyper-rustls")), + all(feature = "with-hyper-rustls", feature = "with-hyper-tls"), + ) +))] +type HyperConnector = hyper::client::HttpConnector; + +// --- Multipart Crates --- + +#[cfg(feature = "with-actix")] +pub(crate) use actix_multipart_rfc7578::client::multipart; +#[cfg(feature = "with-hyper")] +pub(crate) use hyper_multipart_rfc7578::client::multipart; + +// --- Request Types --- #[cfg(feature = "with-actix")] pub(crate) type Request = awc::SendClientRequest; #[cfg(feature = "with-hyper")] pub(crate) type Request = http::Request<hyper::Body>; +// --- Response Types --- + #[cfg(feature = "with-actix")] -pub(crate) type Response = awc::ClientResponse<encoding::Decoder<Payload<PayloadStream>>>; +pub(crate) type Response = awc::ClientResponse< + actix_http::encoding::Decoder<actix_http::Payload<actix_http::PayloadStream>>, +>; #[cfg(feature = "with-hyper")] pub(crate) type Response = http::Response<hyper::Body>; +// --- Client Types ---- + #[cfg(feature = "with-actix")] pub(crate) type Client = awc::Client; #[cfg(feature = "with-hyper")] pub(crate) type Client = hyper::client::Client<HyperConnector, hyper::Body>; +// --- Validations --- + +#[cfg(all(feature = "with-hyper-rustls", feature = "with-hyper-tls"))] +compile_error!("Pick only one of the features: hyper-tls, hyper-rustls"); + #[cfg(not(any(feature = "with-actix", feature = "with-hyper")))] compile_error!("Pick exactly one of these features: with-hyper, with-actix"); |