Trait FromBytes

Source
pub trait FromBytes<const T: usize> {
    // Required methods
    fn from_le_bytes(bytes: [u8; T]) -> Self;
    fn from_be_bytes(bytes: [u8; T]) -> Self;
}
Expand description

Defines a type can be converted from a byte array.

use num_bytes::FromBytes;
let a = [8,0,0,0];
let b = u32::from_le_bytes(a);
assert_eq!(b,8);

Required Methods§

Source

fn from_le_bytes(bytes: [u8; T]) -> Self

Source

fn from_be_bytes(bytes: [u8; T]) -> Self

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 FromBytes<1> for i8

Source§

fn from_le_bytes(bytes: [u8; 1]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 1]) -> Self

Source§

impl FromBytes<1> for u8

Source§

fn from_le_bytes(bytes: [u8; 1]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 1]) -> Self

Source§

impl FromBytes<2> for i16

Source§

fn from_le_bytes(bytes: [u8; 2]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 2]) -> Self

Source§

impl FromBytes<2> for u16

Source§

fn from_le_bytes(bytes: [u8; 2]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 2]) -> Self

Source§

impl FromBytes<4> for f32

Source§

fn from_le_bytes(bytes: [u8; 4]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 4]) -> Self

Source§

impl FromBytes<4> for i32

Source§

fn from_le_bytes(bytes: [u8; 4]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 4]) -> Self

Source§

impl FromBytes<4> for u32

Source§

fn from_le_bytes(bytes: [u8; 4]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 4]) -> Self

Source§

impl FromBytes<8> for f64

Source§

fn from_le_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 8]) -> Self

Source§

impl FromBytes<8> for i64

Source§

fn from_le_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 8]) -> Self

Source§

impl FromBytes<8> for isize

Source§

fn from_le_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 8]) -> Self

Source§

impl FromBytes<8> for u64

Source§

fn from_le_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 8]) -> Self

Source§

impl FromBytes<8> for usize

Source§

fn from_le_bytes(bytes: [u8; 8]) -> Self

Source§

fn from_be_bytes(bytes: [u8; 8]) -> Self

Implementors§