Trait LengthType

Source
pub unsafe trait LengthType
where Self: Copy + Sized + Eq + Ord + Add<Output = Self> + Shr<Output = Self> + Sub<Output = Self> + From<u8> + TryFrom<usize>, usize: TryFrom<Self>,
{ const MIN_VALUE: Self; const MAX_VALUE: Self; const ONE_VALUE: Self; const ZERO_VALUE: Self; // Required methods fn as_usize(self) -> usize; fn usize_as_self(input: usize) -> Self; fn checked_add(self, rhs: Self) -> Option<Self>; fn checked_sub(self, rhs: Self) -> Option<Self>; fn wrapping_add(self, rhs: Self) -> Self; }
Expand description

This trait is used for letting you specify the type of the length and capacity fields of a flex array container, As well as indexing operations. If you have some other type that you want to use and behaves like an unsigned integer, you can implement this trait for it.

It’s marked as unsafe since your type must be continuous and ordered. under common operations such as addition multiplication like integers.

Required Associated Constants§

Source

const MIN_VALUE: Self

The minimum value for this type.

Source

const MAX_VALUE: Self

The maximum value for this type.

Source

const ONE_VALUE: Self

The representation of 1 for this type.

Source

const ZERO_VALUE: Self

The representation of 0 for this type.

Required Methods§

Source

fn as_usize(self) -> usize

Converts this type to a usize. This will only be called when the value by FlexArr`` if the same value at some point successfully used usize::try_from(self)`.

An implementation could be simple as: Self as usize

Source

fn usize_as_self(input: usize) -> Self

Converts a usize to this type. This will only be called when the value by FlexArr`` if the value at some point successfully used Self::try_from(input)` was a successful conversion.

Source

fn checked_add(self, rhs: Self) -> Option<Self>

The same as checked_add for rust’s built in types.

Source

fn checked_sub(self, rhs: Self) -> Option<Self>

The same as checked_sub for rust’s built in types.

Source

fn wrapping_add(self, rhs: Self) -> Self

The same as wrapping_add for rust’s built in types.

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 MIN_VALUE: Self = 0u8

Source§

const MAX_VALUE: Self = 255u8

Source§

const ONE_VALUE: Self = 1u8

Source§

const ZERO_VALUE: Self = 0u8

Source§

fn as_usize(self) -> usize

Source§

fn usize_as_self(input: usize) -> Self

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Source§

impl LengthType for u16

Source§

const MIN_VALUE: Self = 0u16

Source§

const MAX_VALUE: Self = 65_535u16

Source§

const ONE_VALUE: Self = 1u16

Source§

const ZERO_VALUE: Self = 0u16

Source§

fn as_usize(self) -> usize

Source§

fn usize_as_self(input: usize) -> Self

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Source§

impl LengthType for u32

Source§

const MIN_VALUE: Self = 0u32

Source§

const MAX_VALUE: Self = 4_294_967_295u32

Source§

const ONE_VALUE: Self = 1u32

Source§

const ZERO_VALUE: Self = 0u32

Source§

fn as_usize(self) -> usize

Source§

fn usize_as_self(input: usize) -> Self

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Source§

impl LengthType for u64

Source§

const MIN_VALUE: Self = 0u64

Source§

const MAX_VALUE: Self = 18_446_744_073_709_551_615u64

Source§

const ONE_VALUE: Self = 1u64

Source§

const ZERO_VALUE: Self = 0u64

Source§

fn as_usize(self) -> usize

Source§

fn usize_as_self(input: usize) -> Self

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Source§

impl LengthType for u128

Source§

const MIN_VALUE: Self = 0u128

Source§

const MAX_VALUE: Self = 340_282_366_920_938_463_463_374_607_431_768_211_455u128

Source§

const ONE_VALUE: Self = 1u128

Source§

const ZERO_VALUE: Self = 0u128

Source§

fn as_usize(self) -> usize

Source§

fn usize_as_self(input: usize) -> Self

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Source§

impl LengthType for usize

Source§

const MIN_VALUE: Self = 0usize

Source§

const MAX_VALUE: Self = 18_446_744_073_709_551_615usize

Source§

const ONE_VALUE: Self = 1usize

Source§

const ZERO_VALUE: Self = 0usize

Source§

fn as_usize(self) -> usize

Source§

fn usize_as_self(input: usize) -> Self

Source§

fn checked_add(self, rhs: Self) -> Option<Self>

Source§

fn checked_sub(self, rhs: Self) -> Option<Self>

Source§

fn wrapping_add(self, rhs: Self) -> Self

Implementors§