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>
impl<R> AsyncContentLengthStream<R>
Sourcepub fn new(
initial_buffer: Vec<u8>,
reader: R,
content_length: usize,
config: &StreamingBodyConfig,
) -> Self
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 parserreader- The async reader for remaining bytescontent_length- Expected total body sizeconfig- Streaming configuration
Sourcepub fn with_defaults(
initial_buffer: Vec<u8>,
reader: R,
content_length: usize,
) -> Self
pub fn with_defaults( initial_buffer: Vec<u8>, reader: R, content_length: usize, ) -> Self
Create a Content-Length stream with default config.
Sourcepub fn expected_size(&self) -> usize
pub fn expected_size(&self) -> usize
Returns the expected total size.
Sourcepub fn bytes_read(&self) -> usize
pub fn bytes_read(&self) -> usize
Returns the number of bytes read so far.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Returns true if the stream is complete.
Trait Implementations§
Auto Trait Implementations§
impl<R> Freeze for AsyncContentLengthStream<R>where
R: Freeze,
impl<R> RefUnwindSafe for AsyncContentLengthStream<R>where
R: RefUnwindSafe,
impl<R> Send for AsyncContentLengthStream<R>where
R: Send,
impl<R> Sync for AsyncContentLengthStream<R>where
R: Sync,
impl<R> Unpin for AsyncContentLengthStream<R>where
R: Unpin,
impl<R> UnwindSafe for AsyncContentLengthStream<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<S> StreamExt for S
impl<S> StreamExt for S
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
Transforms each item using an async closure.
Source§fn zip<S2>(self, other: S2) -> Zip<Self, S2>
fn zip<S2>(self, other: S2) -> Zip<Self, S2>
Zips this stream with another stream, yielding pairs.
Source§fn filter<P>(self, predicate: P) -> Filter<Self, P>
fn filter<P>(self, predicate: P) -> Filter<Self, P>
Yields only items that match the predicate.
Source§fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
Filters and transforms items in one step.
Source§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
Takes items while the predicate is true.
Source§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
Skips items while the predicate is true.
Source§fn buffered(self, n: usize) -> Buffered<Self>
fn buffered(self, n: usize) -> Buffered<Self>
Buffers up to
n futures, preserving output order.Source§fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
Buffers up to
n futures, yielding results as they complete.Source§fn chunks(self, size: usize) -> Chunks<Self>where
Self: Sized,
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,
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>
fn fold<Acc, F>(self, init: Acc, f: F) -> Fold<Self, F, Acc>
Folds all items into a single value.
Source§fn for_each_async<F, Fut>(self, f: F) -> ForEachAsync<Self, F, Fut>
fn for_each_async<F, Fut>(self, f: F) -> ForEachAsync<Self, F, Fut>
Executes an async closure for each item.
Source§fn try_collect<T, E, C>(self) -> TryCollect<Self, C>
fn try_collect<T, E, C>(self) -> TryCollect<Self, C>
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>
fn try_fold<T, E, Acc, F>(self, init: Acc, f: F) -> TryFold<Self, F, Acc>
Folds a stream of Results, short-circuiting on error.
Source§fn try_for_each<F, E>(self, f: F) -> TryForEach<Self, F>
fn try_for_each<F, E>(self, f: F) -> TryForEach<Self, F>
Executes a fallible closure for each item, short-circuiting on error.