pub trait VarIntWrite {
// Required method
fn write_var_int(&mut self, n: VarInt) -> Result<()>;
}
Expand description
The Write trait for this VarInt or VarLong struct.
This trait is implemented for all io::Write
’s.
§Examples
Cursor
s 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
cur.write_var_int(var_int).unwrap();
// now the var_int is written to cur.
assert_eq!(cur.into_inner(), vec![0xff, 0xff, 0xff, 0xff, 0x07]);
}