pub trait ReadVarint {
// Required methods
fn read_varint(&mut self) -> Result<u64>;
fn read_signed_varint(&mut self) -> Result<i64>;
}Expand description
A trait for reading varint integers from a stream.
The API here is explicitly limited to u64 and i64 in order to reduce
code size.
§Example
use pw_stream::{Cursor, ReadVarint};
let mut cursor = Cursor::new(vec![0xfe, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0x0f]);
let unsigned_value = cursor.read_varint().unwrap();
let signed_value = cursor.read_signed_varint().unwrap();
assert_eq!(unsigned_value, 0xffff_fffe);
assert_eq!(signed_value, i32::MIN.into());Required Methods§
Sourcefn read_varint(&mut self) -> Result<u64>
fn read_varint(&mut self) -> Result<u64>
Read an unsigned varint from the stream.
Errors that may be returned are dependant on the underlying implementation.
Sourcefn read_signed_varint(&mut self) -> Result<i64>
fn read_signed_varint(&mut self) -> Result<i64>
Read a signed varint from the stream.
Errors that may be returned are dependant on the underlying implementation.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".