Trait mc_varint::VarIntWrite[][src]

pub trait VarIntWrite {
    fn write_var_int(&mut self, n: VarInt) -> Result<()>;

The Write trait for this VarInt or VarLong struct.

This trait is implemented for all io::Write's.


Cursors implement io::Write, thus implement VarIntWrite and VarLongWrite:

extern crate mc_varint;

use mc_varint::{VarInt, VarIntWrite};
use std::io::Cursor;

fn main() {
    // firstly we create a Cursor and a VarInt
    let mut cur = Cursor::new(Vec::with_capacity(5));
    let var_int = VarInt::from(2147483647);
    // secondly we write to it
    // now the var_int is written to cur.
    assert_eq!(cur.into_inner(), vec![0xff, 0xff, 0xff, 0xff, 0x07]);

Required Methods

Writes a VarInt or Varlong to self.

The current position is advanced according to the length of VarInt or VarLong.


If this function encounters any form of underlying I/O or other error, an error variant will be returned.