Trait mc_varint::VarLongRead[][src]

pub trait VarLongRead {
    fn read_var_long(&mut self) -> Result<VarLong>;
}

The Read trait for this VarInt or VarLong struct.

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

Examples

Cursors implement io::Read, thus implement VarIntRead and VarLongRead:

extern crate mc_varint;

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

fn main() {
    // firstly we create a Cursor
    let mut cur = Cursor::new(vec![0xff, 0xff, 0xff, 0xff, 0x07]);
    // secondly we write the VarInt to the Cursor
    let var_int = cur.read_var_int().unwrap();
    // the value of var_int is 2147483647
    assert_eq!(var_int, VarInt::from(2147483647));
}

Required Methods

Reads a VarInt or Varlong from self.

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

Errors

If the VarInt or VarLong to read from self is too long (is invalid) or this function encounters any form of underlying I/O or other error, an error variant will be returned.

Implementors