Skip to main content

Leb128WriteExt

Trait Leb128WriteExt 

Source
pub trait Leb128WriteExt: ByteOutput {
    // Provided methods
    fn write_uleb_u8(&mut self, value: u8) -> Result<()> { ... }
    fn write_uleb_u16(&mut self, value: u16) -> Result<()> { ... }
    fn write_uleb_u32(&mut self, value: u32) -> Result<()> { ... }
    fn write_uleb_u64(&mut self, value: u64) -> Result<()> { ... }
    fn write_uleb_u128(&mut self, value: u128) -> Result<()> { ... }
    fn write_uleb_usize(&mut self, value: usize) -> Result<()> { ... }
    fn write_sleb_i8(&mut self, value: i8) -> Result<()> { ... }
    fn write_sleb_i16(&mut self, value: i16) -> Result<()> { ... }
    fn write_sleb_i32(&mut self, value: i32) -> Result<()> { ... }
    fn write_sleb_i64(&mut self, value: i64) -> Result<()> { ... }
    fn write_sleb_i128(&mut self, value: i128) -> Result<()> { ... }
    fn write_sleb_isize(&mut self, value: isize) -> Result<()> { ... }
}
Expand description

Extension methods for writing canonical LEB128 integers to byte streams.

§Target-width integers

usize and isize methods use the current Rust target’s pointer width. Prefer fixed-width integer methods such as Self::write_uleb_u64 or Self::write_sleb_i64 for persistent files and cross-platform protocols.

§Partial writes

These methods are not transactional. An output error may occur after the output has accepted a byte prefix of the encoded value, and those bytes are not rolled back. Calling a method again encodes the entire value from the output’s current position and may duplicate that prefix. Recovery requires outer framing, a trusted seek or rollback strategy, or a transactional transport. Output acceptance does not imply durable persistence.

§Examples

Write a canonical unsigned LEB128 value:

use qubit_io_binary::Leb128WriteExt;

let mut bytes = Vec::new();
bytes.write_uleb_u64(300)?;
assert_eq!(bytes, [0xac, 0x02]);

Provided Methods§

Source

fn write_uleb_u8(&mut self, value: u8) -> Result<()>

Writes an unsigned LEB128 u8.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_uleb_u16(&mut self, value: u16) -> Result<()>

Writes an unsigned LEB128 u16.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_uleb_u32(&mut self, value: u32) -> Result<()>

Writes an unsigned LEB128 u32.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_uleb_u64(&mut self, value: u64) -> Result<()>

Writes an unsigned LEB128 u64.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_uleb_u128(&mut self, value: u128) -> Result<()>

Writes an unsigned LEB128 u128.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_uleb_usize(&mut self, value: usize) -> Result<()>

Writes an unsigned LEB128 usize.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_sleb_i8(&mut self, value: i8) -> Result<()>

Writes a signed LEB128 i8.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_sleb_i16(&mut self, value: i16) -> Result<()>

Writes a signed LEB128 i16.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_sleb_i32(&mut self, value: i32) -> Result<()>

Writes a signed LEB128 i32.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_sleb_i64(&mut self, value: i64) -> Result<()>

Writes a signed LEB128 i64.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_sleb_i128(&mut self, value: i128) -> Result<()>

Writes a signed LEB128 i128.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Source

fn write_sleb_isize(&mut self, value: isize) -> Result<()>

Writes a signed LEB128 isize.

§Parameters
  • value: Integer to encode and write.
§Returns

Returns after the canonical payload has been written.

§Errors

Returns an output error, including a write-zero error when the output stops making progress.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<W> Leb128WriteExt for W
where W: ByteOutput + ?Sized,