zerovec::ule

Trait AsULE

Source
pub trait AsULE: Copy {
    type ULE: ULE;

    // Required methods
    fn to_unaligned(self) -> Self::ULE;
    fn from_unaligned(unaligned: Self::ULE) -> Self;
}
Expand description

A trait for any type that has a 1:1 mapping with an unaligned little-endian (ULE) type.

If you need to implement this trait, consider using #[make_ule] instead.

Required Associated Types§

Source

type ULE: ULE

The ULE type corresponding to Self.

Types having infallible conversions from all bit values (Plain Old Data) can use RawBytesULE with the desired width; for example, u32 uses RawBytesULE<4>.

Types that are not well-defined for all bit values should implement a custom ULE.

Required Methods§

Source

fn to_unaligned(self) -> Self::ULE

Converts from Self to Self::ULE.

This function may involve byte order swapping (native-endian to little-endian).

For best performance, mark your implementation of this function #[inline].

Source

fn from_unaligned(unaligned: Self::ULE) -> Self

Converts from Self::ULE to Self.

This function may involve byte order swapping (little-endian to native-endian).

For best performance, mark your implementation of this function #[inline].

§Safety

This function is infallible because bit validation should have occurred when Self::ULE was first constructed. An implementation may therefore involve an unsafe{} block, like from_bytes_unchecked().

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 AsULE for bool

Source§

type ULE = bool

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for char

Source§

type ULE = CharULE

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for f32

Source§

type ULE = RawBytesULE<4>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for f64

Source§

type ULE = RawBytesULE<8>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for i8

Source§

type ULE = i8

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for i16

Source§

type ULE = RawBytesULE<2>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for i32

Source§

type ULE = RawBytesULE<4>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for i64

Source§

type ULE = RawBytesULE<8>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for i128

Source§

type ULE = RawBytesULE<16>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for u8

Source§

type ULE = u8

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for u16

Source§

type ULE = RawBytesULE<2>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for u32

Source§

type ULE = RawBytesULE<4>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for u64

Source§

type ULE = RawBytesULE<8>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for u128

Source§

type ULE = RawBytesULE<16>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for NonZeroI8

Source§

type ULE = NonZero<u8>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl AsULE for NonZeroU8

Source§

type ULE = NonZero<u8>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl<A: AsULE, B: AsULE> AsULE for (A, B)

Source§

type ULE = Tuple2ULE<<A as AsULE>::ULE, <B as AsULE>::ULE>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl<A: AsULE, B: AsULE, C: AsULE> AsULE for (A, B, C)

Source§

type ULE = Tuple3ULE<<A as AsULE>::ULE, <B as AsULE>::ULE, <C as AsULE>::ULE>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl<A: AsULE, B: AsULE, C: AsULE, D: AsULE> AsULE for (A, B, C, D)

Source§

type ULE = Tuple4ULE<<A as AsULE>::ULE, <B as AsULE>::ULE, <C as AsULE>::ULE, <D as AsULE>::ULE>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl<A: AsULE, B: AsULE, C: AsULE, D: AsULE, E: AsULE> AsULE for (A, B, C, D, E)

Source§

type ULE = Tuple5ULE<<A as AsULE>::ULE, <B as AsULE>::ULE, <C as AsULE>::ULE, <D as AsULE>::ULE, <E as AsULE>::ULE>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl<A: AsULE, B: AsULE, C: AsULE, D: AsULE, E: AsULE, F: AsULE> AsULE for (A, B, C, D, E, F)

Source§

type ULE = Tuple6ULE<<A as AsULE>::ULE, <B as AsULE>::ULE, <C as AsULE>::ULE, <D as AsULE>::ULE, <E as AsULE>::ULE, <F as AsULE>::ULE>

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Source§

impl<T: AsULE> AsULE for Option<T>

Source§

impl<T: AsULE, const N: usize> AsULE for [T; N]

Source§

type ULE = [<T as AsULE>::ULE; N]

Source§

fn to_unaligned(self) -> Self::ULE

Source§

fn from_unaligned(unaligned: Self::ULE) -> Self

Implementors§

Source§

impl AsULE for UnvalidatedChar

Source§

impl<U: AsULE, const N: usize> AsULE for NichedOption<U, N>
where U::ULE: NicheBytes<N>,