[−][src]Trait varint_rs::VarintWriter
The VarintWriter
trait enable writing of varints.
This is pre-implemented on structures which implement std::io::Write
.
Example
If you would like to implement VarintWriter
for a type, you'll have to
specify a VarintWriter::Error
and create the VarintWriter::write
method.
As an example, this is how std::io::Write
is implemented:
use varint_rs::VarintWriter; use std::io; // we are implementing `VarintWriter` for all `std::io::Write` implementors impl<W: io::Write> VarintWriter for W { // writing can cause an error so we give it the appropriate error value type Error = io::Error; // now we can implement the write function which will write the next u8 value(s) // of the varint fn write(&mut self, byte: u8) -> Result<(), Self::Error> { // i won't explain this as the implementation will be specific to the // type you're implementing on match io::Write::write_all(self, &[byte]) { Ok(_) => Ok(()), Err(error) => Err(error) } } }
Associated Types
Loading content...Required methods
Loading content...Provided methods
pub fn write_i8_varint(&mut self, value: i8) -> Result<(), Self::Error>
[src]
Writes an i8 to a signed 8-bit varint.
pub fn write_u8_varint(&mut self, value: u8) -> Result<(), Self::Error>
[src]
Writes a u8 to an unsigned 8-bit varint.
pub fn write_i16_varint(&mut self, value: i16) -> Result<(), Self::Error>
[src]
Writes an i16 to a signed 16-bit varint.
pub fn write_u16_varint(&mut self, value: u16) -> Result<(), Self::Error>
[src]
Writes a u16 to an unsigned 16-bit varint.
pub fn write_i32_varint(&mut self, value: i32) -> Result<(), Self::Error>
[src]
Writes an i32 to a signed 32-bit varint.
pub fn write_u32_varint(&mut self, value: u32) -> Result<(), Self::Error>
[src]
Writes a u32 to an unsigned 32-bit varint.
pub fn write_i64_varint(&mut self, value: i64) -> Result<(), Self::Error>
[src]
Writes an i64 to a signed 64-bit varint.
pub fn write_u64_varint(&mut self, value: u64) -> Result<(), Self::Error>
[src]
Writes a u64 to an unsigned 64-bit varint.
pub fn write_i128_varint(&mut self, value: i128) -> Result<(), Self::Error>
[src]
Writes an i128 to a signed 128-bit varint.
pub fn write_u128_varint(&mut self, value: u128) -> Result<(), Self::Error>
[src]
Writes a u128 to an unsigned 128-bit varint.
pub fn write_isize_varint(&mut self, value: isize) -> Result<(), Self::Error>
[src]
Writes an isize to a signed size-bit varint.
pub fn write_usize_varint(&mut self, value: usize) -> Result<(), Self::Error>
[src]
Writes a usize to an unsigned size-bit varint.