Skip to content

Commit

Permalink
refactor(body): refactor incoming body feature config
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Mar 20, 2024
1 parent b5a2248 commit 46d4d43
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/body/incoming/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ enum Kind {
}

impl Incoming {
#[cfg(all(feature = "http1", any(feature = "client", feature = "server")))]
pub(crate) fn channel(content_length: DecodedLength, wanter: bool) -> (Sender, Incoming) {
let (tx, chan) = ChanBody::new(content_length, wanter);
(tx, Incoming::new(Kind::Chan(chan)))
}

fn new(kind: Kind) -> Incoming {
Incoming { kind }
}
Expand All @@ -71,22 +65,32 @@ impl Incoming {
pub(crate) fn empty() -> Incoming {
Incoming::new(Kind::Empty)
}
}

#[cfg(feature = "ffi")]
pub(crate) fn ffi() -> Incoming {
Incoming::new(Kind::Ffi(crate::ffi::UserBody::new()))
#[cfg(any(feature = "client", feature = "server"))]
impl Incoming {
#[cfg(feature = "http1")]
pub(crate) fn channel(content_length: DecodedLength, wanter: bool) -> (Sender, Incoming) {
let (tx, chan) = ChanBody::new(content_length, wanter);
(tx, Incoming::new(Kind::Chan(chan)))
}

#[cfg(all(feature = "http2", any(feature = "client", feature = "server")))]
#[cfg(feature = "http2")]
pub(crate) fn h2(
recv: ::h2::RecvStream,
content_length: DecodedLength,
ping: ping::Recorder,
) -> Self {
Incoming::new(Kind::H2(H2Body::new(recv, content_length, ping)))
}
}

#[cfg(feature = "ffi")]
impl Incoming {
pub(crate) fn ffi() -> Incoming {
Incoming::new(Kind::Ffi(crate::ffi::UserBody::new()))
}

#[cfg(feature = "ffi")]
pub(crate) fn as_ffi_mut(&mut self) -> &mut crate::ffi::UserBody {
match self.kind {
Kind::Ffi(ref mut body) => return body,
Expand Down

0 comments on commit 46d4d43

Please sign in to comment.