[−][src]Trait varint_rs::VarintReader
The VarintReader
trait enables reading of varints.
This is pre-implemented on structures which implement std::io::Read
.
Example
If you would like to implement VarintReader
for a type, you'll have to
specify a VarintReader::Error
and create the VarintReader::read
method.
As an example, this is how std::io::Read
is implemented:
use varint_rs::VarintReader; use std::io; // we are implementing `VarintReader` for all `std::io::Read` implementors impl<R: io::Read> VarintReader for R { // reading can cause an error so we give it the appropriate error value type Error = io::Error; // now we can implement the read function which will read the next u8 value // for the varint fn read(&mut self) -> Result<u8, Self::Error> { // i won't explain this as the implementation will be specific to the // type you're implementing on let mut buf: [u8; 1] = [0]; match io::Read::read(self, &mut buf) { Ok(count) => { if count == 1 { Ok(buf[0]) } else { Err(io::Error::new(io::ErrorKind::UnexpectedEof, "could not read byte")) } }, Err(error) => Err(error) } } }
Associated Types
Loading content...Required methods
Loading content...Provided methods
pub fn read_i8_varint(&mut self) -> Result<i8, Self::Error>
[src]
Reads an i8 from a signed 8-bit varint.
pub fn read_u8_varint(&mut self) -> Result<u8, Self::Error>
[src]
Reads a u8 from an unsigned 8-bit varint.
pub fn read_i16_varint(&mut self) -> Result<i16, Self::Error>
[src]
Reads an i16 from a signed 16-bit varint.
pub fn read_u16_varint(&mut self) -> Result<u16, Self::Error>
[src]
Reads a u16 from an unsigned 16-bit varint.
pub fn read_i32_varint(&mut self) -> Result<i32, Self::Error>
[src]
Reads an i32 from a signed 32-bit varint.
pub fn read_u32_varint(&mut self) -> Result<u32, Self::Error>
[src]
Reads a u32 from an unsigned 32-bit varint.
pub fn read_i64_varint(&mut self) -> Result<i64, Self::Error>
[src]
Reads an i64 from a signed 64-bit varint.
pub fn read_u64_varint(&mut self) -> Result<u64, Self::Error>
[src]
Reads a u64 from an unsigned 64-bit varint.
pub fn read_i128_varint(&mut self) -> Result<i128, Self::Error>
[src]
Reads an i128 from a signed 128-bit varint.
pub fn read_u128_varint(&mut self) -> Result<u128, Self::Error>
[src]
Reads a u128 from an unsigned 128-bit varint.
pub fn read_isize_varint(&mut self) -> Result<isize, Self::Error>
[src]
Reads an isize from a signed size-bit varint.
pub fn read_usize_varint(&mut self) -> Result<usize, Self::Error>
[src]
Reads a usize from an unsigned size-bit varint.