Trait VarIntRead

Source
pub trait VarIntRead {
    // Required method
    fn read_var_int(&mut self) -> Result<VarInt>;
}
Expand description

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§

Source

fn read_var_int(&mut self) -> Result<VarInt>

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§

Source§

impl<R> VarIntRead for R
where R: Read,