Skip to main content

AsyncContentLengthStream

Struct AsyncContentLengthStream 

Source
pub struct AsyncContentLengthStream<R> { /* private fields */ }
Expand description

An async stream that reads a Content-Length body in chunks.

This stream first yields any buffered data from the parser, then continues reading from the underlying async reader until the expected length is reached.

§Memory Efficiency

Only one chunk is buffered at a time, making this suitable for streaming large request bodies without excessive memory usage.

Implementations§

Source§

impl<R> AsyncContentLengthStream<R>
where R: AsyncRead + Unpin + Send + Sync + 'static,

Source

pub fn new( initial_buffer: Vec<u8>, reader: R, content_length: usize, config: &StreamingBodyConfig, ) -> Self

Create a new Content-Length stream.

§Arguments
  • initial_buffer - Any bytes already buffered by the parser
  • reader - The async reader for remaining bytes
  • content_length - Expected total body size
  • config - Streaming configuration
Source

pub fn with_defaults( initial_buffer: Vec<u8>, reader: R, content_length: usize, ) -> Self

Create a Content-Length stream with default config.

Source

pub fn expected_size(&self) -> usize

Returns the expected total size.

Source

pub fn bytes_read(&self) -> usize

Returns the number of bytes read so far.

Source

pub fn remaining(&self) -> usize

Returns the remaining bytes to read.

Source

pub fn is_complete(&self) -> bool

Returns true if the stream is complete.

Trait Implementations§

Source§

impl<R> Stream for AsyncContentLengthStream<R>
where R: AsyncRead + Unpin + Send + Sync + 'static,

Source§

type Item = Result<Vec<u8>, RequestBodyStreamError>

The type of values yielded by the stream.
Source§

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>

Attempt to pull out the next value of this stream. Read more
Source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the stream. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<S> StreamExt for S
where S: Stream + ?Sized,

Source§

fn next(&mut self) -> Next<'_, Self>
where Self: Unpin,

Returns the next item from the stream.
Source§

fn map<T, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> T,

Transforms each item using a closure.
Source§

fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
where Self: Sized, F: FnMut(Self::Item) -> Fut, Fut: Future,

Transforms each item using an async closure.
Source§

fn chain<S2>(self, other: S2) -> Chain<Self, S2>
where Self: Sized, S2: Stream<Item = Self::Item>,

Chains this stream with another stream.
Source§

fn zip<S2>(self, other: S2) -> Zip<Self, S2>
where Self: Sized, S2: Stream,

Zips this stream with another stream, yielding pairs.
Source§

fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Yields only items that match the predicate.
Source§

fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Option<T>,

Filters and transforms items in one step.
Source§

fn take(self, n: usize) -> Take<Self>
where Self: Sized,

Takes the first n items.
Source§

fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Takes items while the predicate is true.
Source§

fn skip(self, n: usize) -> Skip<Self>
where Self: Sized,

Skips the first n items.
Source§

fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Skips items while the predicate is true.
Source§

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Enumerates items with their index.
Source§

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Fuses the stream to handle None gracefully.
Source§

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where Self: Sized, F: FnMut(&Self::Item),

Inspects items without modifying the stream.
Source§

fn buffered(self, n: usize) -> Buffered<Self>
where Self: Sized, Self::Item: Future,

Buffers up to n futures, preserving output order.
Source§

fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
where Self: Sized, Self::Item: Future,

Buffers up to n futures, yielding results as they complete.
Source§

fn collect<C>(self) -> Collect<Self, C>
where Self: Sized, C: Default + Extend<Self::Item>,

Collects all items into a collection.
Source§

fn chunks(self, size: usize) -> Chunks<Self>
where Self: Sized,

Collects items into fixed-size chunks.
Source§

fn ready_chunks(self, size: usize) -> ReadyChunks<Self>
where Self: Sized,

Yields immediately available items up to a maximum chunk size.
Source§

fn fold<Acc, F>(self, init: Acc, f: F) -> Fold<Self, F, Acc>
where Self: Sized, F: FnMut(Acc, Self::Item) -> Acc,

Folds all items into a single value.
Source§

fn for_each<F>(self, f: F) -> ForEach<Self, F>
where Self: Sized, F: FnMut(Self::Item),

Executes a closure for each item.
Source§

fn for_each_async<F, Fut>(self, f: F) -> ForEachAsync<Self, F, Fut>
where Self: Sized, F: FnMut(Self::Item) -> Fut, Fut: Future<Output = ()>,

Executes an async closure for each item.
Source§

fn count(self) -> Count<Self>
where Self: Sized,

Counts the number of items in the stream.
Source§

fn any<P>(self, predicate: P) -> Any<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Checks if any item matches the predicate.
Source§

fn all<P>(self, predicate: P) -> All<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Checks if all items match the predicate.
Source§

fn try_collect<T, E, C>(self) -> TryCollect<Self, C>
where Self: Sized + Stream<Item = Result<T, E>>, C: Default + Extend<T>,

Collects items from a stream of Results, short-circuiting on error.
Source§

fn try_fold<T, E, Acc, F>(self, init: Acc, f: F) -> TryFold<Self, F, Acc>
where Self: Sized + Stream<Item = Result<T, E>>, F: FnMut(Acc, T) -> Result<Acc, E>,

Folds a stream of Results, short-circuiting on error.
Source§

fn try_for_each<F, E>(self, f: F) -> TryForEach<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Result<(), E>,

Executes a fallible closure for each item, short-circuiting on error.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ResponseProduces<T> for T