pub trait ChunkSource {
type Error;
type Chunk<'a>: AsRef<[u8]> + 'a
where Self: 'a;
// Required method
fn next_chunk<'a>(
&'a mut self,
) -> Option<Result<Self::Chunk<'a>, Self::Error>>;
}
Expand description
This trait is designed to handle byte streams efficiently, especially when the
source needs to borrow from an internal buffer between calls. A simple closure
(FnMut() -> Option<Result<B, E>>
) cannot express this lifetime relationship,
as the returned slice would need to outlive the closure call itself. This trait
solves that by making the source a mutable object that you call repeatedly.
Async functionality can be achieved by the original API
Required Associated Types§
Required Methods§
Sourcefn next_chunk<'a>(&'a mut self) -> Option<Result<Self::Chunk<'a>, Self::Error>>
fn next_chunk<'a>(&'a mut self) -> Option<Result<Self::Chunk<'a>, Self::Error>>
Get the next chunk of bytes.
Returns None
when the source is exhausted, Some(Ok(bytes))
for a successful chunk,
or Some(Err(e))
if an error occurred.
The returned slice is valid until the next call to next_chunk
or until the
source is dropped.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.