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>>;
}unescape_stream_into! macro.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>>
👎Deprecated since 0.3.1: This sync-only trait is superseded by the runtime-agnostic unescape_stream_into! macro.
fn next_chunk<'a>(&'a mut self) -> Option<Result<Self::Chunk<'a>, Self::Error>>
unescape_stream_into! macro.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.
Implementations on Foreign Types§
Source§impl<T> ChunkSource for &mut Twhere
T: ChunkSource,
impl<T> ChunkSource for &mut Twhere
T: ChunkSource,
Source§type Error = <T as ChunkSource>::Error
type Error = <T as ChunkSource>::Error
unescape_stream_into! macro.Source§type Chunk<'a> = <T as ChunkSource>::Chunk<'a>
where
Self: 'a
type Chunk<'a> = <T as ChunkSource>::Chunk<'a> where Self: 'a
unescape_stream_into! macro.