pub struct Reader<'a> { /* private fields */ }Expand description
A cursor over bytes that reads what the writers above write, and refuses every other spelling: a number in more bytes than it needs, a text that is not UTF-8, and anything that runs past the end.
A refusal is a DecodeError with an empty path, which says at which
byte it happened; whoever reads a value at a type puts its path in.
Implementations§
Source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
Sourcepub fn byte(&mut self) -> Result<u8, DecodeError>
pub fn byte(&mut self) -> Result<u8, DecodeError>
Sourcepub fn bool(&mut self) -> Result<bool, DecodeError>
pub fn bool(&mut self) -> Result<bool, DecodeError>
The next Bool: one byte, 0 or 1.
§Errors
A DecodeError when no bytes are left or the byte is another.
Sourcepub fn uint(&mut self) -> Result<u64, DecodeError>
pub fn uint(&mut self) -> Result<u64, DecodeError>
The next number, which must fit 64 bits.
§Errors
A DecodeError when the input ends inside the number, it takes
more bytes than it needs, or it does not fit 64 bits.
Sourcepub fn count(&mut self) -> Result<usize, DecodeError>
pub fn count(&mut self) -> Result<usize, DecodeError>
The next number as an index or length: one that fits this host’s addresses.
§Errors
As Reader::uint, and when the number does not fit a usize.
Sourcepub fn signed(&mut self) -> Result<i64, DecodeError>
pub fn signed(&mut self) -> Result<i64, DecodeError>
Sourcepub fn biguint(&mut self, max_bits: u64) -> Result<BigUint, DecodeError>
pub fn biguint(&mut self, max_bits: u64) -> Result<BigUint, DecodeError>
The next number, of any size up to max_bits bits. A longer one is
refused as a limit, as soon as it is known to be longer and before
the rest of it is read.
§Errors
A DecodeError when the input ends inside the number or it takes
more bytes than it needs, and a limit when it is longer than
max_bits bits.
Sourcepub fn int(&mut self, limits: &Limits) -> Result<BigInt, DecodeError>
pub fn int(&mut self, limits: &Limits) -> Result<BigInt, DecodeError>
The next signed number, of any size, refused as a limit when its
magnitude takes more than Limits::int_bits.
§Errors
As Reader::biguint, with Limits::int_bits as its bound.
Sourcepub fn bytes(&mut self, limits: &Limits) -> Result<&'a [u8], DecodeError>
pub fn bytes(&mut self, limits: &Limits) -> Result<&'a [u8], DecodeError>
The next run of bytes, its length first, refused as a limit when it
is longer than Limits::text_bytes.
§Errors
A DecodeError when the length does not read, is past the limit,
or is more than the bytes left.
Sourcepub fn text(&mut self, limits: &Limits) -> Result<&'a str, DecodeError>
pub fn text(&mut self, limits: &Limits) -> Result<&'a str, DecodeError>
The next text, its length first: valid UTF-8, and refused as a limit
when it is longer than Limits::text_bytes.
§Errors
As Reader::bytes, and when the bytes are not UTF-8.