Skip to main content

FromByteArray

Trait FromByteArray 

Source
pub unsafe trait FromByteArray: ToByteArray {
    // Required method
    fn from_bytes(bytes: Self::Bytes) -> Self;

    // Provided method
    fn cast_bytes<Dst>(self) -> Dst
       where Dst: FromByteArray<Bytes = Self::Bytes> { ... }
}
Expand description

Types which can be transmuted from a byte array.

These are types for which any bit pattern is valid.

§Safety

This type must only be implemented for types for which any bit pattern is valid.

Required Methods§

Source

fn from_bytes(bytes: Self::Bytes) -> Self

Convert an array of bytes, in native order, into this type.

This is the same as from_ne_bytes for primitive types.

Provided Methods§

Source

fn cast_bytes<Dst>(self) -> Dst
where Dst: FromByteArray<Bytes = Self::Bytes>,

Convert this type to another of the same size.

This should compile to a zero-cost transmute.

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 FromByteArray for f32

Source§

fn from_bytes(val: Self::Bytes) -> Self

Source§

impl FromByteArray for f64

Source§

fn from_bytes(val: Self::Bytes) -> Self

Source§

impl FromByteArray for i8

Source§

fn from_bytes(val: Self::Bytes) -> Self

Source§

impl FromByteArray for i16

Source§

fn from_bytes(val: Self::Bytes) -> Self

Source§

impl FromByteArray for i32

Source§

fn from_bytes(val: Self::Bytes) -> Self

Source§

impl FromByteArray for i64

Source§

fn from_bytes(val: Self::Bytes) -> Self

Source§

impl FromByteArray for u8

Source§

fn from_bytes(val: Self::Bytes) -> Self

Source§

impl FromByteArray for u16

Source§

fn from_bytes(val: Self::Bytes) -> Self

Source§

impl FromByteArray for u32

Source§

fn from_bytes(val: Self::Bytes) -> Self

Source§

impl FromByteArray for u64

Source§

fn from_bytes(val: Self::Bytes) -> Self

Implementors§