pub trait BytesAccess: Sized {
type Claim;
type Error: DeserializeError;
// Required methods
fn fork(&mut self) -> Self;
async fn next_bytes<R>(
self,
f: impl FnOnce(&[u8]) -> R,
) -> Result<Chunk<(Self, R), Self::Claim>, Self::Error>;
}Expand description
Streams a byte string in zero-copy chunks. Obtained from Entry::deserialize_bytes_chunks.
Byte strings are primitives - the type is already known, so no probing or racing is needed. This adapter exists solely for formats that cannot deliver the value as a single contiguous slice.
ⓘ
let mut chunks = hit!(e.deserialize_bytes_chunks().await);
let mut out = Vec::new();
let claim = loop {
match chunks.next_bytes(|b| out.extend_from_slice(b)).await? {
Chunk::Data((new, ())) => chunks = new,
Chunk::Done(claim) => break claim,
}
};Required Associated Types§
Sourcetype Claim
type Claim
Proof-of-consumption token, returned when the byte string is exhausted.
Must match the enclosing Entry::Claim.
Sourcetype Error: DeserializeError
type Error: DeserializeError
Fatal error type; must match the parent Deserializer::Error.
Required Methods§
Sourcefn fork(&mut self) -> Self
fn fork(&mut self) -> Self
Fork a sibling accessor at the same read position.
See StrAccess::fork for full semantics.
Sourceasync fn next_bytes<R>(
self,
f: impl FnOnce(&[u8]) -> R,
) -> Result<Chunk<(Self, R), Self::Claim>, Self::Error>
async fn next_bytes<R>( self, f: impl FnOnce(&[u8]) -> R, ) -> Result<Chunk<(Self, R), Self::Claim>, Self::Error>
Advance to the next chunk, passing it to f.
Ok(Chunk::Data((self, r)))- next chunk processed; accessor returned for the next call.Ok(Chunk::Done(claim))- byte string exhausted; claim is now valid.Err(e)- fatal format error.Pending- no data yet.
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.