Skip to main content

ToByteArray

Trait ToByteArray 

Source
pub unsafe trait ToByteArray: Copy {
    type Align: AsRef<[u8]>;
    type Bytes: AsRef<[u8]>;

    // Required method
    fn to_bytes(self) -> Self::Bytes;
}
Expand description

Types which can be transmuted to a byte array.

§Safety

This type must only be implemented for Copy types which contain no padding.

Required Associated Types§

Source

type Align: AsRef<[u8]>

Array of bytes whose length is equal to the alignment of the type.

Source

type Bytes: AsRef<[u8]>

View of this type as an array of bytes.

Required Methods§

Source

fn to_bytes(self) -> Self::Bytes

Convert this type to an array of bytes in native order.

This is the same as to_ne_bytes for primitive types.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ToByteArray for bool

Source§

type Align = [u8; 1]

Source§

type Bytes = [u8; 1]

Source§

fn to_bytes(self) -> [u8; 1]

Source§

impl ToByteArray for f32

Source§

type Align = [u8; 4]

Source§

type Bytes = [u8; 4]

Source§

fn to_bytes(self) -> Self::Bytes

Source§

impl ToByteArray for f64

Source§

type Align = [u8; 8]

Source§

type Bytes = [u8; 8]

Source§

fn to_bytes(self) -> Self::Bytes

Source§

impl ToByteArray for i8

Source§

type Align = [u8; 1]

Source§

type Bytes = [u8; 1]

Source§

fn to_bytes(self) -> Self::Bytes

Source§

impl ToByteArray for i16

Source§

type Align = [u8; 2]

Source§

type Bytes = [u8; 2]

Source§

fn to_bytes(self) -> Self::Bytes

Source§

impl ToByteArray for i32

Source§

type Align = [u8; 4]

Source§

type Bytes = [u8; 4]

Source§

fn to_bytes(self) -> Self::Bytes

Source§

impl ToByteArray for i64

Source§

type Align = [u8; 8]

Source§

type Bytes = [u8; 8]

Source§

fn to_bytes(self) -> Self::Bytes

Source§

impl ToByteArray for u8

Source§

type Align = [u8; 1]

Source§

type Bytes = [u8; 1]

Source§

fn to_bytes(self) -> Self::Bytes

Source§

impl ToByteArray for u16

Source§

type Align = [u8; 2]

Source§

type Bytes = [u8; 2]

Source§

fn to_bytes(self) -> Self::Bytes

Source§

impl ToByteArray for u32

Source§

type Align = [u8; 4]

Source§

type Bytes = [u8; 4]

Source§

fn to_bytes(self) -> Self::Bytes

Source§

impl ToByteArray for u64

Source§

type Align = [u8; 8]

Source§

type Bytes = [u8; 8]

Source§

fn to_bytes(self) -> Self::Bytes

Implementors§