Skip to main content

ReadVarInt

Trait ReadVarInt 

Source
pub trait ReadVarInt: Read {
    // Provided method
    fn read_varint<T: VarInt>(&mut self) -> Result<T> { ... }
}
Expand description

Extension trait for reading variable-length integers.

Implemented automatically for every type implementing Read.

§Example

use std::io::Cursor;
use orengine_utils::varint::{ReadVarInt, WriteVarInt};

let mut data = Vec::new();
data.write_varint(500u32).unwrap();

let mut reader = Cursor::new(data);

let value: u32 = reader.read_varint().unwrap();

assert_eq!(value, 500);

Provided Methods§

Source

fn read_varint<T: VarInt>(&mut self) -> Result<T>

Reads a VarInt from the reader.

§Example
use std::io::Cursor;
use orengine_utils::varint::{ReadVarInt, WriteVarInt};

let mut data = Vec::new();
data.write_varint(500u32).unwrap();

let mut reader = Cursor::new(data);

let value: u32 = reader.read_varint().unwrap();

assert_eq!(value, 500);

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<R: Read> ReadVarInt for R