mod boxed;
mod collect;
mod combinator;
mod frame;
#[allow(dead_code)] pub(crate) mod incoming;
mod simple;
mod size_hint;
mod stream;
use karmaio::buf::IoBuf;
pub use boxed::BoxBody;
pub use collect::{CollectError, Collected, collect};
pub use combinator::{Either, InspectFrame, MapError, MapFrame, WithTrailers};
pub use frame::Frame;
pub use incoming::{Incoming, IncomingData};
pub use simple::{Empty, Full};
pub use size_hint::SizeHint;
pub use stream::{BodyDataStream, BodyStream, StreamBody};
#[allow(async_fn_in_trait)]
pub trait Body {
type Data: IoBuf;
type Error;
async fn next_frame(&mut self) -> Result<Option<Frame<Self::Data>>, Self::Error>;
#[inline]
fn size_hint(&self) -> SizeHint {
SizeHint::new()
}
#[inline]
fn trailer_hint(&self) -> TrailerHint {
TrailerHint::MayHave
}
#[inline]
fn is_end_stream(&self) -> bool {
false
}
#[inline]
fn recycle(&mut self, data: Self::Data) {
drop(data);
}
}
impl<B: Body + ?Sized> Body for &mut B {
type Data = B::Data;
type Error = B::Error;
#[inline]
async fn next_frame(&mut self) -> Result<Option<Frame<Self::Data>>, Self::Error> {
(**self).next_frame().await
}
#[inline]
fn size_hint(&self) -> SizeHint {
(**self).size_hint()
}
#[inline]
fn trailer_hint(&self) -> TrailerHint {
(**self).trailer_hint()
}
#[inline]
fn is_end_stream(&self) -> bool {
(**self).is_end_stream()
}
#[inline]
fn recycle(&mut self, data: Self::Data) {
(**self).recycle(data);
}
}
#[allow(async_fn_in_trait)]
pub trait BodyExt: Body {
#[inline]
fn boxed<'a>(self) -> BoxBody<'a, Self::Data, Self::Error>
where
Self: Sized + 'a,
{
BoxBody::new(self)
}
async fn collect(mut self, max_bytes: usize) -> Result<Collected, CollectError<Self::Error>>
where
Self: Sized,
{
collect(&mut self, max_bytes).await
}
#[inline]
fn map_err<F, E>(self, map: F) -> MapError<Self, F>
where
Self: Sized,
F: FnMut(Self::Error) -> E,
{
MapError::new(self, map)
}
#[inline]
fn inspect_frame<F>(self, inspect: F) -> InspectFrame<Self, F>
where
Self: Sized,
F: FnMut(&Frame<Self::Data>),
{
InspectFrame::new(self, inspect)
}
#[inline]
fn map_frame<F, D>(self, map: F) -> MapFrame<Self, F>
where
Self: Sized,
F: FnMut(Frame<Self::Data>) -> Frame<D>,
D: IoBuf,
{
MapFrame::new(self, map)
}
#[inline]
fn with_trailers(self, trailers: http::HeaderMap) -> WithTrailers<Self>
where
Self: Sized,
{
WithTrailers::new(self, trailers)
}
#[inline]
fn into_frame_stream(self) -> BodyStream<Self>
where
Self: Sized,
{
BodyStream::new(self)
}
#[inline]
fn into_data_stream(self) -> BodyDataStream<Self>
where
Self: Sized,
{
BodyDataStream::new(self)
}
}
impl<B: Body + ?Sized> BodyExt for B {}
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub enum TrailerHint {
None,
#[default]
MayHave,
}
#[allow(dead_code)]
pub(crate) mod pipe;