Skip to content

Commit 1dfc7ec

Browse files
committed
refactor: use cfg-aliases for feature flags
Introduces aliases for each feature flag as well as for the main combinations of http version and client/server roles. This makes it significantly easier to understand which feature flags are required on any given line as the aliases require less parsing of nested `cfg` expressions.
1 parent c449528 commit 1dfc7ec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+544
-666
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,6 @@ required-features = ["full"]
240240
name = "server"
241241
path = "tests/server.rs"
242242
required-features = ["full"]
243+
244+
[build-dependencies]
245+
cfg_aliases = "0.2.1"

build.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use cfg_aliases::cfg_aliases;
2+
3+
fn main() {
4+
cfg_aliases! {
5+
http1: { feature = "http1" },
6+
http2: { feature = "http2" },
7+
8+
client : { feature = "client" },
9+
server : { feature = "server" },
10+
11+
ffi: { feature = "ffi" },
12+
full: { feature = "full" },
13+
nightly: { feature = "nightly" },
14+
runtime: { feature = "runtime" },
15+
tracing: { feature = "tracing" },
16+
17+
http_client: { all(any(http1, http2), client) },
18+
http1_client: { all(http1, client) },
19+
http2_client: { all(http2, client) },
20+
21+
http_server: { all(any(http1, http2), server) },
22+
http1_server: { all(http1, server) },
23+
http2_server: { all(http2, server) },
24+
}
25+
}

examples/hello-http2.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use http_body_util::Full;
55
use hyper::body::Bytes;
6-
#[cfg(feature = "server")]
6+
#[cfg(server)]
77
use hyper::server::conn::http2;
88
use hyper::service::service_fn;
99
use hyper::{Request, Response};
@@ -19,7 +19,7 @@ use support::TokioIo;
1919

2020
// An async function that consumes a request, does nothing with it and returns a
2121
// response.
22-
#[cfg(feature = "server")]
22+
#[cfg(server)]
2323
async fn hello(_: Request<hyper::body::Incoming>) -> Result<Response<Full<Bytes>>, Infallible> {
2424
Ok(Response::new(Full::new(Bytes::from("Hello, World!"))))
2525
}
@@ -42,7 +42,7 @@ where
4242
}
4343
}
4444

45-
#[cfg(feature = "server")]
45+
#[cfg(server)]
4646
#[tokio::main]
4747
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
4848
pretty_env_logger::init();
@@ -83,7 +83,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
8383
}
8484
}
8585

86-
#[cfg(not(feature = "server"))]
86+
#[cfg(not(server))]
8787
fn main() {
8888
panic!("This example requires the 'server' feature to be enabled");
8989
}

0 commit comments

Comments
 (0)