[−][src]Trait wasabi_leb128::WriteLeb128
A trait that extends writers (implementers of the io::Write
trait) with a method to write
LEB128 encodings of primitive integers.
Required methods
fn write_leb128(&mut self, value: T) -> Result<usize>
Writes a primitive integer value
as a variable-length LEB128 byte sequence into self
.
If successful, it returns the number of bytes written to self
, i.e., the length of the
LEB128 encoding of value
.
Note that there is no specific error type (just the regular io::Error
of the writer)
for encoding integers to LEB128, because all primitive integer values can always be
represented as a (wide enough) LEB128 byte sequence.
Example
use wasabi_leb128::WriteLeb128; // Vec<u8> implements io::Write. let mut buf = Vec::new(); let bytes_written = buf.write_leb128(128u8).unwrap(); assert_eq!(buf, [0x80, 0x01]); assert_eq!(bytes_written, 2);
Implementors
impl<W, T> WriteLeb128<T> for W where
W: Write,
T: PrimInt,
T: AsPrimitive<u8>,
[src]
W: Write,
T: PrimInt,
T: AsPrimitive<u8>,
Combined implementation for writing signed and unsigned primitive integers as LEB128.