refactor(lib): Use cfg(all(...)) instead of multiple cfg attributes
This commit is contained in:
committed by
Sean McArthur
parent
2c8121f173
commit
9dff00425d
@@ -16,8 +16,7 @@ use super::DecodedLength;
|
||||
#[cfg(feature = "stream")]
|
||||
use crate::common::sync_wrapper::SyncWrapper;
|
||||
use crate::common::Future;
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
|
||||
use crate::common::Never;
|
||||
use crate::common::{task, watch, Pin, Poll};
|
||||
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
|
||||
@@ -74,8 +73,7 @@ struct Extra {
|
||||
delayed_eof: Option<DelayEof>,
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
|
||||
type DelayEofUntil = oneshot::Receiver<Never>;
|
||||
|
||||
enum DelayEof {
|
||||
|
||||
@@ -51,8 +51,7 @@ use std::fmt;
|
||||
#[cfg(feature = "http2")]
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
#[cfg(feature = "runtime")]
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(all(feature = "runtime", feature = "http2"))]
|
||||
use std::time::Duration;
|
||||
|
||||
use bytes::Bytes;
|
||||
@@ -63,7 +62,10 @@ use tower_service::Service;
|
||||
|
||||
use super::dispatch;
|
||||
use crate::body::HttpBody;
|
||||
use crate::common::{task, exec::{BoxSendFuture, Exec}, Future, Pin, Poll};
|
||||
use crate::common::{
|
||||
exec::{BoxSendFuture, Exec},
|
||||
task, Future, Pin, Poll,
|
||||
};
|
||||
use crate::proto;
|
||||
use crate::rt::Executor;
|
||||
#[cfg(feature = "http1")]
|
||||
|
||||
@@ -52,8 +52,7 @@
|
||||
pub use self::connect::HttpConnector;
|
||||
|
||||
pub mod connect;
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "runtime")]
|
||||
#[cfg(all(test, feature = "runtime"))]
|
||||
mod tests;
|
||||
|
||||
cfg_feature! {
|
||||
|
||||
@@ -5,8 +5,7 @@ use std::sync::Arc;
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
use crate::body::{Body, HttpBody};
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(feature = "server")]
|
||||
#[cfg(all(feature = "http2", feature = "server"))]
|
||||
use crate::proto::h2::server::H2Stream;
|
||||
use crate::rt::Executor;
|
||||
#[cfg(feature = "server")]
|
||||
|
||||
@@ -8,17 +8,14 @@ macro_rules! ready {
|
||||
}
|
||||
|
||||
pub(crate) mod buf;
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "server")]
|
||||
#[cfg(all(feature = "server", any(feature = "http1", feature = "http2")))]
|
||||
pub(crate) mod date;
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "server")]
|
||||
#[cfg(all(feature = "server", any(feature = "http1", feature = "http2")))]
|
||||
pub(crate) mod drain;
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
pub(crate) mod exec;
|
||||
pub(crate) mod io;
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
|
||||
mod lazy;
|
||||
mod never;
|
||||
#[cfg(feature = "stream")]
|
||||
@@ -26,8 +23,7 @@ pub(crate) mod sync_wrapper;
|
||||
pub(crate) mod task;
|
||||
pub(crate) mod watch;
|
||||
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg(all(feature = "client", any(feature = "http1", feature = "http2")))]
|
||||
pub(crate) use self::lazy::{lazy, Started as Lazy};
|
||||
#[cfg(any(
|
||||
feature = "client",
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
use bytes::BytesMut;
|
||||
use http::header::CONTENT_LENGTH;
|
||||
use http::header::{HeaderValue, ValueIter};
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(feature = "client")]
|
||||
use http::Method;
|
||||
use http::HeaderMap;
|
||||
#[cfg(all(feature = "http2", feature = "client"))]
|
||||
use http::Method;
|
||||
|
||||
#[cfg(feature = "http1")]
|
||||
pub(super) fn connection_keep_alive(value: &HeaderValue) -> bool {
|
||||
@@ -29,8 +28,7 @@ fn connection_has(value: &HeaderValue, needle: &str) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[cfg(feature = "http1")]
|
||||
#[cfg(feature = "server")]
|
||||
#[cfg(all(feature = "http1", feature = "server"))]
|
||||
pub(super) fn content_length_parse(value: &HeaderValue) -> Option<u64> {
|
||||
value.to_str().ok().and_then(|s| s.parse().ok())
|
||||
}
|
||||
@@ -66,8 +64,7 @@ pub(super) fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg(all(feature = "http2", feature = "client"))]
|
||||
pub(super) fn method_has_defined_payload_semantics(method: &Method) -> bool {
|
||||
match *method {
|
||||
Method::GET | Method::HEAD | Method::DELETE | Method::CONNECT => false,
|
||||
|
||||
@@ -37,8 +37,7 @@ pub(crate) type RequestHead = MessageHead<RequestLine>;
|
||||
pub(crate) struct RequestLine(pub(crate) http::Method, pub(crate) http::Uri);
|
||||
|
||||
/// An incoming response message.
|
||||
#[cfg(feature = "http1")]
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg(all(feature = "http1", feature = "client"))]
|
||||
pub(crate) type ResponseHead = MessageHead<http::StatusCode>;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -49,8 +49,7 @@ use std::fmt;
|
||||
use std::marker::PhantomData;
|
||||
#[cfg(feature = "tcp")]
|
||||
use std::net::SocketAddr;
|
||||
#[cfg(feature = "runtime")]
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(all(feature = "runtime", feature = "http2"))]
|
||||
use std::time::Duration;
|
||||
|
||||
use bytes::Bytes;
|
||||
@@ -63,8 +62,7 @@ use crate::common::exec::{ConnStreamExec, Exec, NewSvcExec};
|
||||
#[cfg(feature = "http2")]
|
||||
use crate::common::io::Rewind;
|
||||
use crate::common::{task, Future, Pin, Poll, Unpin};
|
||||
#[cfg(feature = "http1")]
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||
use crate::error::{Kind, Parse};
|
||||
use crate::proto;
|
||||
use crate::service::{HttpService, MakeServiceRef};
|
||||
@@ -107,8 +105,7 @@ enum ConnectionMode {
|
||||
#[cfg(feature = "http2")]
|
||||
H2Only,
|
||||
/// Use HTTP/1 and try to upgrade to h2 when a parse error occurs.
|
||||
#[cfg(feature = "http1")]
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||
Fallback,
|
||||
}
|
||||
|
||||
@@ -160,8 +157,7 @@ where
|
||||
S: HttpService<Body>,
|
||||
{
|
||||
pub(super) conn: Option<ProtoServer<T, S::ResBody, S, E>>,
|
||||
#[cfg(feature = "http1")]
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||
fallback: Fallback<E>,
|
||||
}
|
||||
|
||||
@@ -186,16 +182,14 @@ where
|
||||
H2(#[pin] proto::h2::Server<Rewind<T>, S, B, E>),
|
||||
}
|
||||
|
||||
#[cfg(feature = "http1")]
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||
#[derive(Clone, Debug)]
|
||||
enum Fallback<E> {
|
||||
ToHttp2(proto::h2::server::Config, E),
|
||||
Http1Only,
|
||||
}
|
||||
|
||||
#[cfg(feature = "http1")]
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||
impl<E> Fallback<E> {
|
||||
fn to_h2(&self) -> bool {
|
||||
match *self {
|
||||
@@ -205,8 +199,7 @@ impl<E> Fallback<E> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "http1")]
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||
impl<E> Unpin for Fallback<E> {}
|
||||
|
||||
/// Deconstructed parts of a `Connection`.
|
||||
@@ -701,8 +694,7 @@ where
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "http1")]
|
||||
#[cfg(feature = "http2")]
|
||||
#[cfg(all(feature = "http1", feature = "http2"))]
|
||||
fn upgrade_h2(&mut self) {
|
||||
trace!("Trying to upgrade connection to h2");
|
||||
let conn = self.conn.take();
|
||||
|
||||
@@ -39,20 +39,16 @@ pub use tower_service::Service;
|
||||
|
||||
mod http;
|
||||
mod make;
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))]
|
||||
mod oneshot;
|
||||
mod util;
|
||||
|
||||
pub(super) use self::http::HttpService;
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))]
|
||||
pub(super) use self::make::MakeConnection;
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "server")]
|
||||
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "server"))]
|
||||
pub(super) use self::make::MakeServiceRef;
|
||||
#[cfg(any(feature = "http1", feature = "http2"))]
|
||||
#[cfg(feature = "client")]
|
||||
#[cfg(all(any(feature = "http1", feature = "http2"), feature = "client"))]
|
||||
pub(super) use self::oneshot::{oneshot, Oneshot};
|
||||
|
||||
pub use self::make::make_service_fn;
|
||||
|
||||
Reference in New Issue
Block a user