Skip to content

Commit be2024a

Browse files
tottotoseanmonstar
authored andcommitted
refactor(body): remove lint config to allow unused code
1 parent 883cb5a commit be2024a

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

src/body/incoming.rs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
use std::fmt;
2+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
23
use std::future::Future;
34
use std::pin::Pin;
45
use std::task::{Context, Poll};
56

67
use bytes::Bytes;
78
use futures_channel::mpsc;
89
use futures_channel::oneshot;
10+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
911
use futures_util::{stream::FusedStream, Stream}; // for mpsc::Receiver
1012
use http::HeaderMap;
1113
use http_body::{Body, Frame, SizeHint};
1214

15+
#[cfg(all(
16+
any(feature = "http1", feature = "http2"),
17+
any(feature = "client", feature = "server")
18+
))]
1319
use super::DecodedLength;
1420
use crate::common::watch;
1521
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
@@ -39,8 +45,8 @@ pub struct Incoming {
3945
}
4046

4147
enum Kind {
42-
#[allow(dead_code)]
4348
Empty,
49+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
4450
Chan {
4551
content_length: DecodedLength,
4652
want_tx: watch::Sender,
@@ -86,11 +92,12 @@ impl Incoming {
8692
///
8793
/// Useful when wanting to stream chunks from another thread.
8894
#[inline]
89-
#[allow(unused)]
95+
#[cfg(test)]
9096
pub(crate) fn channel() -> (Sender, Incoming) {
9197
Self::new_channel(DecodedLength::CHUNKED, /*wanter =*/ false)
9298
}
9399

100+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
94101
pub(crate) fn new_channel(content_length: DecodedLength, wanter: bool) -> (Sender, Incoming) {
95102
let (data_tx, data_rx) = mpsc::channel(0);
96103
let (trailers_tx, trailers_rx) = oneshot::channel();
@@ -171,11 +178,26 @@ impl Body for Incoming {
171178
type Error = crate::Error;
172179

173180
fn poll_frame(
181+
#[cfg_attr(
182+
not(all(
183+
any(feature = "http1", feature = "http2"),
184+
any(feature = "client", feature = "server")
185+
)),
186+
allow(unused_mut)
187+
)]
174188
mut self: Pin<&mut Self>,
189+
#[cfg_attr(
190+
not(all(
191+
any(feature = "http1", feature = "http2"),
192+
any(feature = "client", feature = "server")
193+
)),
194+
allow(unused_variables)
195+
)]
175196
cx: &mut Context<'_>,
176197
) -> Poll<Option<Result<Frame<Self::Data>, Self::Error>>> {
177198
match self.kind {
178199
Kind::Empty => Poll::Ready(None),
200+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
179201
Kind::Chan {
180202
content_length: ref mut len,
181203
ref mut data_rx,
@@ -247,6 +269,7 @@ impl Body for Incoming {
247269
fn is_end_stream(&self) -> bool {
248270
match self.kind {
249271
Kind::Empty => true,
272+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
250273
Kind::Chan { content_length, .. } => content_length == DecodedLength::ZERO,
251274
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
252275
Kind::H2 { recv: ref h2, .. } => h2.is_end_stream(),
@@ -256,6 +279,10 @@ impl Body for Incoming {
256279
}
257280

258281
fn size_hint(&self) -> SizeHint {
282+
#[cfg(all(
283+
any(feature = "http1", feature = "http2"),
284+
any(feature = "client", feature = "server")
285+
))]
259286
macro_rules! opt_len {
260287
($content_length:expr) => {{
261288
let mut hint = SizeHint::default();
@@ -270,6 +297,7 @@ impl Body for Incoming {
270297

271298
match self.kind {
272299
Kind::Empty => SizeHint::with_exact(0),
300+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
273301
Kind::Chan { content_length, .. } => opt_len!(content_length),
274302
#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
275303
Kind::H2 { content_length, .. } => opt_len!(content_length),
@@ -289,6 +317,13 @@ impl fmt::Debug for Incoming {
289317
let mut builder = f.debug_tuple("Body");
290318
match self.kind {
291319
Kind::Empty => builder.field(&Empty),
320+
#[cfg(any(
321+
all(
322+
any(feature = "http1", feature = "http2"),
323+
any(feature = "client", feature = "server")
324+
),
325+
feature = "ffi"
326+
))]
292327
_ => builder.field(&Streaming),
293328
};
294329

src/body/length.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ impl DecodedLength {
4040
}
4141

4242
/// Converts to an Option<u64> representing a Known or Unknown length.
43+
#[cfg(all(
44+
any(feature = "http1", feature = "http2"),
45+
any(feature = "client", feature = "server")
46+
))]
4347
pub(crate) fn into_opt(self) -> Option<u64> {
4448
match self {
4549
DecodedLength::CHUNKED | DecodedLength::CLOSE_DELIMITED => None,
@@ -58,6 +62,10 @@ impl DecodedLength {
5862
}
5963
}
6064

65+
#[cfg(all(
66+
any(feature = "http1", feature = "http2"),
67+
any(feature = "client", feature = "server")
68+
))]
6169
pub(crate) fn sub_if(&mut self, amt: u64) {
6270
match *self {
6371
DecodedLength::CHUNKED | DecodedLength::CLOSE_DELIMITED => (),

src/body/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ pub use self::incoming::Incoming;
2828

2929
#[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))]
3030
pub(crate) use self::incoming::Sender;
31+
#[cfg(all(
32+
any(feature = "http1", feature = "http2"),
33+
any(feature = "client", feature = "server")
34+
))]
3135
pub(crate) use self::length::DecodedLength;
3236

3337
mod incoming;

src/common/watch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Value = usize;
1515

1616
pub(crate) const CLOSED: usize = 0;
1717

18+
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
1819
pub(crate) fn channel(initial: Value) -> (Sender, Receiver) {
1920
debug_assert!(
2021
initial != CLOSED,

0 commit comments

Comments
 (0)