Trait VarIntTarget

Source
pub trait VarIntTarget:
    Debug
    + Eq
    + PartialEq
    + PartialOrd
    + Sized
    + Copy {
    type Signed: SignedVarIntTarget;

    const MAX_VARINT_BYTES: u8;
    const MAX_LAST_VARINT_BYTE: u8;

    // Required methods
    fn vector_to_num(res: [u8; 16]) -> Self;
    fn scalar_to_num(x: u64) -> Self;
    fn cast_u32(num: u32) -> Self;
    fn cast_u64(num: u64) -> Self;
    fn num_to_scalar_stage1(self) -> u64;
    fn num_to_vector_stage1(self) -> [u8; 16];
    fn zigzag(from: Self::Signed) -> Self;
    fn unzigzag(self) -> Self::Signed;
}
Expand description

Represents an unsigned scalar value that can be encoded to and decoded from a varint.

Required Associated Constants§

Source

const MAX_VARINT_BYTES: u8

The maximum length of varint that is necessary to represent this number

Source

const MAX_LAST_VARINT_BYTE: u8

The maximum value of the last byte if the varint is MAX_VARINT_BYTES long such that the varint would not overflow the target

Required Associated Types§

Source

type Signed: SignedVarIntTarget

The signed version of this type

Required Methods§

Source

fn vector_to_num(res: [u8; 16]) -> Self

Converts a 128-bit vector to this number

Note: Despite operating on 128-bit SIMD vectors, these functions accept and return static arrays due to a lack of optimization capability by the compiler when passing or returning intrinsic vectors.

Source

fn scalar_to_num(x: u64) -> Self

Source

fn cast_u32(num: u32) -> Self

Cast from u32 to self

Source

fn cast_u64(num: u64) -> Self

Cast from u64 to self

Source

fn num_to_scalar_stage1(self) -> u64

Splits this number into 7-bit segments for encoding

Source

fn num_to_vector_stage1(self) -> [u8; 16]

Splits this number into 7-bit segments for encoding

Source

fn zigzag(from: Self::Signed) -> Self

ZigZag encodes this value

Source

fn unzigzag(self) -> Self::Signed

ZigZag decodes this value

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 VarIntTarget for u8

Source§

const MAX_VARINT_BYTES: u8 = 2u8

Source§

const MAX_LAST_VARINT_BYTE: u8 = 1u8

Source§

type Signed = i8

Source§

fn vector_to_num(res: [u8; 16]) -> Self

Source§

fn scalar_to_num(x: u64) -> Self

Source§

fn cast_u32(num: u32) -> Self

Source§

fn cast_u64(num: u64) -> Self

Source§

fn num_to_scalar_stage1(self) -> u64

Source§

fn num_to_vector_stage1(self) -> [u8; 16]

Source§

fn zigzag(from: Self::Signed) -> Self

Source§

fn unzigzag(self) -> Self::Signed

Source§

impl VarIntTarget for u16

Source§

const MAX_VARINT_BYTES: u8 = 3u8

Source§

const MAX_LAST_VARINT_BYTE: u8 = 3u8

Source§

type Signed = i16

Source§

fn vector_to_num(res: [u8; 16]) -> Self

Source§

fn scalar_to_num(x: u64) -> Self

Source§

fn cast_u32(num: u32) -> Self

Source§

fn cast_u64(num: u64) -> Self

Source§

fn num_to_scalar_stage1(self) -> u64

Source§

fn num_to_vector_stage1(self) -> [u8; 16]

Source§

fn zigzag(from: Self::Signed) -> Self

Source§

fn unzigzag(self) -> Self::Signed

Source§

impl VarIntTarget for u32

Source§

const MAX_VARINT_BYTES: u8 = 5u8

Source§

const MAX_LAST_VARINT_BYTE: u8 = 15u8

Source§

type Signed = i32

Source§

fn vector_to_num(res: [u8; 16]) -> Self

Source§

fn scalar_to_num(x: u64) -> Self

Source§

fn cast_u32(num: u32) -> Self

Source§

fn cast_u64(num: u64) -> Self

Source§

fn num_to_scalar_stage1(self) -> u64

Source§

fn num_to_vector_stage1(self) -> [u8; 16]

Source§

fn zigzag(from: Self::Signed) -> Self

Source§

fn unzigzag(self) -> Self::Signed

Source§

impl VarIntTarget for u64

Source§

const MAX_VARINT_BYTES: u8 = 10u8

Source§

const MAX_LAST_VARINT_BYTE: u8 = 1u8

Source§

type Signed = i64

Source§

fn scalar_to_num(_x: u64) -> Self

Source§

fn num_to_scalar_stage1(self) -> u64

Source§

fn vector_to_num(res: [u8; 16]) -> Self

Source§

fn num_to_vector_stage1(self) -> [u8; 16]

Source§

fn cast_u32(num: u32) -> Self

Source§

fn cast_u64(num: u64) -> Self

Source§

fn zigzag(from: Self::Signed) -> Self

Source§

fn unzigzag(self) -> Self::Signed

Implementors§