pub struct Reader<'a> { /* private fields */ }Expand description
Reads canonical encodings from a byte slice. Lengths and counts are checked against the field’s limit and the remaining input before anything is allocated.
Implementations§
Source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
Sourcepub fn string(&mut self, max: usize) -> Result<&'a str, DecodeError>
pub fn string(&mut self, max: usize) -> Result<&'a str, DecodeError>
string of at most max bytes; valid UTF-8, not normalised.
§Errors
As Self::bytes, or DecodeError::InvalidUtf8.
Sourcepub fn option<T>(
&mut self,
f: impl FnOnce(&mut Self) -> Result<T, DecodeError>,
) -> Result<Option<T>, DecodeError>
pub fn option<T>( &mut self, f: impl FnOnce(&mut Self) -> Result<T, DecodeError>, ) -> Result<Option<T>, DecodeError>
option<T> with the value read by f; tags other than 0x00/0x01 are errors.
§Errors
DecodeError::InvalidOptionTag, or whatever f returns.
Sourcepub fn list<T>(
&mut self,
max: usize,
f: impl FnMut(&mut Self) -> Result<T, DecodeError>,
) -> Result<Vec<T>, DecodeError>
pub fn list<T>( &mut self, max: usize, f: impl FnMut(&mut Self) -> Result<T, DecodeError>, ) -> Result<Vec<T>, DecodeError>
list<T> of at most max elements, each read by f.
§Errors
DecodeError::OverLimit, DecodeError::Truncated, or whatever f returns.
Source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
Sourcepub const fn finish(self) -> Result<(), DecodeError>
pub const fn finish(self) -> Result<(), DecodeError>
Sourcepub fn peek_u8(&self) -> Result<u8, DecodeError>
pub fn peek_u8(&self) -> Result<u8, DecodeError>
Sourcepub fn u8(&mut self) -> Result<u8, DecodeError>
pub fn u8(&mut self) -> Result<u8, DecodeError>
Sourcepub fn u16(&mut self) -> Result<u16, DecodeError>
pub fn u16(&mut self) -> Result<u16, DecodeError>
Sourcepub fn u32(&mut self) -> Result<u32, DecodeError>
pub fn u32(&mut self) -> Result<u32, DecodeError>
Sourcepub fn u64(&mut self) -> Result<u64, DecodeError>
pub fn u64(&mut self) -> Result<u64, DecodeError>
Sourcepub fn bool(&mut self) -> Result<bool, DecodeError>
pub fn bool(&mut self) -> Result<bool, DecodeError>
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Reader<'a>
impl<'a> RefUnwindSafe for Reader<'a>
impl<'a> Send for Reader<'a>
impl<'a> Sync for Reader<'a>
impl<'a> Unpin for Reader<'a>
impl<'a> UnsafeUnpin for Reader<'a>
impl<'a> UnwindSafe for Reader<'a>
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