LengthType

Trait LengthType 

Source
pub trait LengthType:
    Copy
    + Default
    + PartialOrd {
    const SIZE: usize;

    // Required methods
    fn from_usize(value: usize) -> Option<Self>;
    fn to_usize(self) -> usize;
}
Expand description

Trait for length types used in slice collections.

This trait defines the interface for length types that can be used to represent the length of string cows. Implementations are provided for u8, u16, u32, and u64.

Required Associated Constants§

Source

const SIZE: usize

Size of the length type in bytes.

Required Methods§

Source

fn from_usize(value: usize) -> Option<Self>

Convert a usize value to this length type.

Returns None if the value is too large to be represented by this length type.

Source

fn to_usize(self) -> usize

Convert this length value to usize.

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

Source§

const SIZE: usize = 1usize

Source§

fn from_usize(value: usize) -> Option<Self>

Source§

fn to_usize(self) -> usize

Source§

impl LengthType for u16

Source§

const SIZE: usize = 2usize

Source§

fn from_usize(value: usize) -> Option<Self>

Source§

fn to_usize(self) -> usize

Source§

impl LengthType for u32

Source§

const SIZE: usize = 4usize

Source§

fn from_usize(value: usize) -> Option<Self>

Source§

fn to_usize(self) -> usize

Source§

impl LengthType for u64

Source§

const SIZE: usize = 8usize

Source§

fn from_usize(value: usize) -> Option<Self>

Source§

fn to_usize(self) -> usize

Implementors§