VarintWriter

Trait VarintWriter 

Source
pub trait VarintWriter {
    type Error;

Show 13 methods // Required method fn write(&mut self, byte: u8) -> Result<(), Self::Error>; // Provided methods fn write_i8_varint(&mut self, value: i8) -> Result<(), Self::Error> { ... } fn write_u8_varint(&mut self, value: u8) -> Result<(), Self::Error> { ... } fn write_i16_varint(&mut self, value: i16) -> Result<(), Self::Error> { ... } fn write_u16_varint(&mut self, value: u16) -> Result<(), Self::Error> { ... } fn write_i32_varint(&mut self, value: i32) -> Result<(), Self::Error> { ... } fn write_u32_varint(&mut self, value: u32) -> Result<(), Self::Error> { ... } fn write_i64_varint(&mut self, value: i64) -> Result<(), Self::Error> { ... } fn write_u64_varint(&mut self, value: u64) -> Result<(), Self::Error> { ... } fn write_i128_varint(&mut self, value: i128) -> Result<(), Self::Error> { ... } fn write_u128_varint(&mut self, value: u128) -> Result<(), Self::Error> { ... } fn write_isize_varint(&mut self, value: isize) -> Result<(), Self::Error> { ... } fn write_usize_varint(&mut self, value: usize) -> Result<(), Self::Error> { ... }
}
Expand description

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)
    }
  }
}

Required Associated Types§

Required Methods§

Source

fn write(&mut self, byte: u8) -> Result<(), Self::Error>

Writes the next u8 for the varint.

Provided Methods§

Source

fn write_i8_varint(&mut self, value: i8) -> Result<(), Self::Error>

Writes an i8 to a signed 8-bit varint.

Source

fn write_u8_varint(&mut self, value: u8) -> Result<(), Self::Error>

Writes a u8 to an unsigned 8-bit varint.

Source

fn write_i16_varint(&mut self, value: i16) -> Result<(), Self::Error>

Writes an i16 to a signed 16-bit varint.

Source

fn write_u16_varint(&mut self, value: u16) -> Result<(), Self::Error>

Writes a u16 to an unsigned 16-bit varint.

Source

fn write_i32_varint(&mut self, value: i32) -> Result<(), Self::Error>

Writes an i32 to a signed 32-bit varint.

Source

fn write_u32_varint(&mut self, value: u32) -> Result<(), Self::Error>

Writes a u32 to an unsigned 32-bit varint.

Source

fn write_i64_varint(&mut self, value: i64) -> Result<(), Self::Error>

Writes an i64 to a signed 64-bit varint.

Source

fn write_u64_varint(&mut self, value: u64) -> Result<(), Self::Error>

Writes a u64 to an unsigned 64-bit varint.

Source

fn write_i128_varint(&mut self, value: i128) -> Result<(), Self::Error>

Writes an i128 to a signed 128-bit varint.

Source

fn write_u128_varint(&mut self, value: u128) -> Result<(), Self::Error>

Writes a u128 to an unsigned 128-bit varint.

Source

fn write_isize_varint(&mut self, value: isize) -> Result<(), Self::Error>

Writes an isize to a signed size-bit varint.

Source

fn write_usize_varint(&mut self, value: usize) -> Result<(), Self::Error>

Writes a usize to an unsigned size-bit varint.

Implementors§