From 129f884c511babbb41be3acfb247a075d1ba679f Mon Sep 17 00:00:00 2001 From: Ferris Tseng Date: Mon, 8 Feb 2021 23:17:45 -0500 Subject: cleaning up feature flag hell --- ipfs-api/src/lib.rs | 55 ++++++++++++++++++++++++++++++++++------------------- 1 file 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 @@ -156,24 +156,20 @@ //! ``` //! -#[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; +type HyperConnector = hyper_tls::HttpsConnector; #[cfg(all(feature = "with-hyper-rustls", not(feature = "with-hyper-tls")))] -type HyperConnector = hyper_rustls::HttpsConnector; -#[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; +#[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; +// --- Response Types --- + #[cfg(feature = "with-actix")] -pub(crate) type Response = awc::ClientResponse>>; +pub(crate) type Response = awc::ClientResponse< + actix_http::encoding::Decoder>, +>; #[cfg(feature = "with-hyper")] pub(crate) type Response = http::Response; +// --- Client Types ---- + #[cfg(feature = "with-actix")] pub(crate) type Client = awc::Client; #[cfg(feature = "with-hyper")] pub(crate) type Client = hyper::client::Client; +// --- 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"); -- cgit v1.2.3