Varint

Trait Varint 

Source
pub trait Varint:
    Clone
    + Copy
    + Debug
    + Default
    + Eq
    + Hash
    + Ord
    + PartialEq
    + PartialOrd
    + Sized
    + Sealed {
    type Buf: Default + 'static;

    const MAX_LEN: usize;

    // Required methods
    fn encoded_len(self) -> usize;
    fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>;
    fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
       where I: IntoIterator<Item = u8>;
    fn write(self, buf: &mut Self::Buf) -> &[u8] ;
    fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>;
}
Expand description

An integer that can be LEB128-encoded.

Required Associated Constants§

Source

const MAX_LEN: usize

The maximum size in bytes of the encoded integer.

Required Associated Types§

Source

type Buf: Default + 'static

A fixed-size buffer.

Is always [u8; Self::MAX_LEN].

Required Methods§

Source

fn encoded_len(self) -> usize

Returns the number of bytes needed to encode the integer.

Source

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Decodes a LEB128-encoded integer from buf.

It returns the decoded integer and the number of bytes read.

Source

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Decodes a LEB128-encoded integer from iter.

It returns the decoded integer and the number of bytes read.

Source

fn write(self, buf: &mut Self::Buf) -> &[u8]

Encodes x into buf in LEB128 format, returning the portion of buf that was written to.

Source

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Tries to encode x in LEB128 format.

It returns the portion of buf that was written to, or None if buf is too small to fit x.

In order to succeed, buf should be at least encoded_len bytes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Varint for i8

Source§

const MAX_LEN: usize = 2usize

Source§

type Buf = [u8; 2]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for i16

Source§

const MAX_LEN: usize = 3usize

Source§

type Buf = [u8; 3]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for i32

Source§

const MAX_LEN: usize = 5usize

Source§

type Buf = [u8; 5]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for i64

Source§

const MAX_LEN: usize = 10usize

Source§

type Buf = [u8; 10]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for i128

Source§

const MAX_LEN: usize = 19usize

Source§

type Buf = [u8; 19]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for isize

Source§

const MAX_LEN: usize = 10usize

Source§

type Buf = [u8; 10]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for u8

Source§

const MAX_LEN: usize = 2usize

Source§

type Buf = [u8; 2]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for u16

Source§

const MAX_LEN: usize = 3usize

Source§

type Buf = [u8; 3]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for u32

Source§

const MAX_LEN: usize = 5usize

Source§

type Buf = [u8; 5]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for u64

Source§

const MAX_LEN: usize = 10usize

Source§

type Buf = [u8; 10]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for u128

Source§

const MAX_LEN: usize = 19usize

Source§

type Buf = [u8; 19]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Source§

impl Varint for usize

Source§

const MAX_LEN: usize = 10usize

Source§

type Buf = [u8; 10]

Source§

fn encoded_len(self) -> usize

Source§

fn read(buf: &[u8]) -> Result<(Self, usize), Overflow>

Source§

fn read_iter<I>(iter: I) -> Result<(Self, usize), Overflow>
where I: IntoIterator<Item = u8>,

Source§

fn write(self, buf: &mut Self::Buf) -> &[u8]

Source§

fn try_write(self, buf: &mut [u8]) -> Option<&[u8]>

Implementors§