pub struct ValueReader<'c, 'r, 'b> { /* private fields */ }Expand description
Reads values at their types from bytes, within limits: the runtime’s
own values (read_value), and a Rust value its
Shaped mapping reads part by part, with no
runtime value between.
Implementations§
Source§impl<'b> ValueReader<'_, '_, 'b>
impl<'b> ValueReader<'_, '_, 'b>
Sourcepub fn mismatch(&self, ty: &Type) -> DecodeError
pub fn mismatch(&self, ty: &Type) -> DecodeError
The refusal of a value read at ty, a type the Rust type does not
map to, or a value of it that is none of the Rust type’s.
Sourcepub fn unit(&mut self, ty: &Type) -> Result<(), DecodeError>
pub fn unit(&mut self, ty: &Type) -> Result<(), DecodeError>
Reads Unit at ty.
§Errors
When ty is not Unit; so for every reader below and its type, and
for bytes that are not a value of it within the limits.
Sourcepub fn set<T: Shaped + Ord>(
&mut self,
ty: &Type,
) -> Result<BTreeSet<T>, DecodeError>
pub fn set<T: Shaped + Ord>( &mut self, ty: &Type, ) -> Result<BTreeSet<T>, DecodeError>
Reads a set, its elements in ascending order.
§Errors
When ty is no set, the bytes are not one of Ts, or its elements
are out of order or repeat.
Sourcepub fn dict<K: Shaped + Ord, V: Shaped>(
&mut self,
ty: &Type,
) -> Result<BTreeMap<K, V>, DecodeError>
pub fn dict<K: Shaped + Ord, V: Shaped>( &mut self, ty: &Type, ) -> Result<BTreeMap<K, V>, DecodeError>
Reads a dictionary, its entries in ascending order of their keys.
§Errors
When ty is no dictionary, the bytes are not one of Ks and Vs,
or its keys are out of order or repeat.
Sourcepub fn tuple<T>(
&mut self,
ty: &Type,
read: impl FnOnce(&mut Self, &mut Fields) -> Result<T, DecodeError>,
) -> Result<T, DecodeError>
pub fn tuple<T>( &mut self, ty: &Type, read: impl FnOnce(&mut Self, &mut Fields) -> Result<T, DecodeError>, ) -> Result<T, DecodeError>
Reads a tuple, its parts by read.
§Errors
When ty is no tuple, or read refuses or leaves a part unread.
Sourcepub fn record<T>(
&mut self,
ty: &Type,
read: impl FnOnce(&mut Self, &mut Fields) -> Result<T, DecodeError>,
) -> Result<T, DecodeError>
pub fn record<T>( &mut self, ty: &Type, read: impl FnOnce(&mut Self, &mut Fields) -> Result<T, DecodeError>, ) -> Result<T, DecodeError>
Reads a record, its fields by read in declaration order.
§Errors
When ty is no record, or read refuses or leaves a field unread.
Sourcepub fn variant<T>(
&mut self,
ty: &Type,
read: impl FnOnce(&mut Self, usize, &mut Fields) -> Result<T, DecodeError>,
) -> Result<T, DecodeError>
pub fn variant<T>( &mut self, ty: &Type, read: impl FnOnce(&mut Self, usize, &mut Fields) -> Result<T, DecodeError>, ) -> Result<T, DecodeError>
Reads a value of the enum ty, Option and Result included:
read is given its constructor’s index and reads its payload.
§Errors
When ty is no enum, the bytes name a constructor it does not have,
or read refuses or leaves a part unread.
Sourcepub fn newtype<T: Shaped>(&mut self, ty: &Type) -> Result<T, DecodeError>
pub fn newtype<T: Shaped>(&mut self, ty: &Type) -> Result<T, DecodeError>
Reads a value of the newtype ty as its base’s T, held to the form
ty has, if any.
§Errors
When ty is no newtype, the bytes are not a T of its base, or the
value is out of its form.
Sourcepub fn encoded(&mut self, ty: &Type) -> Result<&'b [u8], DecodeError>
pub fn encoded(&mut self, ty: &Type) -> Result<&'b [u8], DecodeError>
Reads one value of ty, checked as crate::read_value checks it,
and gives its bytes.
§Errors
When the bytes are not a value of ty within the limits.