Trait ToBytes

Source
pub trait ToBytes {
    // Required methods
    fn to_le_byte_vec(_: Self) -> Vec<u8> ;
    fn write_to_slice(self, target: &mut [u8]);

    // Provided methods
    fn try_to_le_byte_vec(
        var: Self,
        _max_len: usize,
    ) -> Result<Vec<u8>, BrickletError>
       where Self: Sized { ... }
    fn try_write_to_slice(
        self,
        _max_len: usize,
        target: &mut [u8],
    ) -> Result<(), BrickletError>
       where Self: Sized { ... }
}
Expand description

A trait to serialize the implementing type to a byte vector.

Required Methods§

Source

fn to_le_byte_vec(_: Self) -> Vec<u8>

Serialize the implementing type to a byte vector.

Source

fn write_to_slice(self, target: &mut [u8])

Provided Methods§

Source

fn try_to_le_byte_vec( var: Self, _max_len: usize, ) -> Result<Vec<u8>, BrickletError>
where Self: Sized,

Try to serialize the implementing type to a byte vector. If the type is shorter than max_len, it will be padded with zero bytes. Currently this method is only used for strings. Other types use the standard implementation, which calls to_le_byte_vec without further checks or padding.

§Errors

Returns an InvalidArgument error if the type was too long.

Source

fn try_write_to_slice( self, _max_len: usize, target: &mut [u8], ) -> Result<(), BrickletError>
where Self: Sized,

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

Source§

fn to_le_byte_vec(b: bool) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for char

Source§

fn to_le_byte_vec(c: char) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for f32

Source§

fn to_le_byte_vec(num: f32) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for f64

Source§

fn to_le_byte_vec(num: f64) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for i8

Source§

fn to_le_byte_vec(num: i8) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for i16

Source§

fn to_le_byte_vec(num: i16) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for i32

Source§

fn to_le_byte_vec(num: i32) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for i64

Source§

fn to_le_byte_vec(num: i64) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for u8

Source§

fn to_le_byte_vec(num: u8) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for u16

Source§

fn to_le_byte_vec(num: u16) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for u32

Source§

fn to_le_byte_vec(num: u32) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for u64

Source§

fn to_le_byte_vec(num: u64) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for ()

Source§

fn to_le_byte_vec(_: ()) -> Vec<u8>

Source§

fn write_to_slice(self, _target: &mut [u8])

Source§

impl ToBytes for String

Source§

fn to_le_byte_vec(s: String) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

fn try_to_le_byte_vec( s: String, max_len: usize, ) -> Result<Vec<u8>, BrickletError>

Source§

fn try_write_to_slice( self, max_len: usize, target: &mut [u8], ) -> Result<(), BrickletError>
where Self: Sized,

Source§

impl ToBytes for [bool; 2]

Source§

fn to_le_byte_vec(arr: [bool; 2]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 3]

Source§

fn to_le_byte_vec(arr: [bool; 3]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 4]

Source§

fn to_le_byte_vec(arr: [bool; 4]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 5]

Source§

fn to_le_byte_vec(arr: [bool; 5]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 8]

Source§

fn to_le_byte_vec(arr: [bool; 8]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 10]

Source§

fn to_le_byte_vec(arr: [bool; 10]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 13]

Source§

fn to_le_byte_vec(arr: [bool; 13]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 16]

Source§

fn to_le_byte_vec(arr: [bool; 16]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 24]

Source§

fn to_le_byte_vec(arr: [bool; 24]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 32]

Source§

fn to_le_byte_vec(arr: [bool; 32]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 168]

Source§

fn to_le_byte_vec(arr: [bool; 168]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 432]

Source§

fn to_le_byte_vec(arr: [bool; 432]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 440]

Source§

fn to_le_byte_vec(arr: [bool; 440]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 448]

Source§

fn to_le_byte_vec(arr: [bool; 448]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 464]

Source§

fn to_le_byte_vec(arr: [bool; 464]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 472]

Source§

fn to_le_byte_vec(arr: [bool; 472]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [bool; 480]

Source§

fn to_le_byte_vec(arr: [bool; 480]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [char; 4]

Source§

fn to_le_byte_vec(arr: [char; 4]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [char; 5]

Source§

fn to_le_byte_vec(arr: [char; 5]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [char; 56]

Source§

fn to_le_byte_vec(arr: [char; 56]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [char; 58]

Source§

fn to_le_byte_vec(arr: [char; 58]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [char; 59]

Source§

fn to_le_byte_vec(arr: [char; 59]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [char; 60]

Source§

fn to_le_byte_vec(arr: [char; 60]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [char; 61]

Source§

fn to_le_byte_vec(arr: [char; 61]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [char; 62]

Source§

fn to_le_byte_vec(arr: [char; 62]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [char; 63]

Source§

fn to_le_byte_vec(arr: [char; 63]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [f32; 3]

Source§

fn to_le_byte_vec(arr: [f32; 3]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [f32; 15]

Source§

fn to_le_byte_vec(arr: [f32; 15]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i8; 4]

Source§

fn to_le_byte_vec(arr: [i8; 4]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i8; 32]

Source§

fn to_le_byte_vec(arr: [i8; 32]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i8; 60]

Source§

fn to_le_byte_vec(arr: [i8; 60]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i16; 3]

Source§

fn to_le_byte_vec(arr: [i16; 3]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i16; 4]

Source§

fn to_le_byte_vec(arr: [i16; 4]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i16; 7]

Source§

fn to_le_byte_vec(arr: [i16; 7]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i16; 10]

Source§

fn to_le_byte_vec(arr: [i16; 10]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i16; 14]

Source§

fn to_le_byte_vec(arr: [i16; 14]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i16; 30]

Source§

fn to_le_byte_vec(arr: [i16; 30]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i32; 2]

Source§

fn to_le_byte_vec(arr: [i32; 2]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i32; 4]

Source§

fn to_le_byte_vec(arr: [i32; 4]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i32; 6]

Source§

fn to_le_byte_vec(arr: [i32; 6]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [i64; 4]

Source§

fn to_le_byte_vec(arr: [i64; 4]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 3]

Source§

fn to_le_byte_vec(arr: [u8; 3]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 4]

Source§

fn to_le_byte_vec(arr: [u8; 4]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 6]

Source§

fn to_le_byte_vec(arr: [u8; 6]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 7]

Source§

fn to_le_byte_vec(arr: [u8; 7]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 8]

Source§

fn to_le_byte_vec(arr: [u8; 8]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 10]

Source§

fn to_le_byte_vec(arr: [u8; 10]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 12]

Source§

fn to_le_byte_vec(arr: [u8; 12]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 15]

Source§

fn to_le_byte_vec(arr: [u8; 15]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 16]

Source§

fn to_le_byte_vec(arr: [u8; 16]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 20]

Source§

fn to_le_byte_vec(arr: [u8; 20]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 32]

Source§

fn to_le_byte_vec(arr: [u8; 32]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 52]

Source§

fn to_le_byte_vec(arr: [u8; 52]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 56]

Source§

fn to_le_byte_vec(arr: [u8; 56]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 58]

Source§

fn to_le_byte_vec(arr: [u8; 58]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 59]

Source§

fn to_le_byte_vec(arr: [u8; 59]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 60]

Source§

fn to_le_byte_vec(arr: [u8; 60]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 61]

Source§

fn to_le_byte_vec(arr: [u8; 61]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 62]

Source§

fn to_le_byte_vec(arr: [u8; 62]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 63]

Source§

fn to_le_byte_vec(arr: [u8; 63]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u8; 64]

Source§

fn to_le_byte_vec(arr: [u8; 64]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u16; 2]

Source§

fn to_le_byte_vec(arr: [u16; 2]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u16; 4]

Source§

fn to_le_byte_vec(arr: [u16; 4]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u16; 7]

Source§

fn to_le_byte_vec(arr: [u16; 7]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u16; 8]

Source§

fn to_le_byte_vec(arr: [u16; 8]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u16; 10]

Source§

fn to_le_byte_vec(arr: [u16; 10]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u16; 20]

Source§

fn to_le_byte_vec(arr: [u16; 20]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u16; 27]

Source§

fn to_le_byte_vec(arr: [u16; 27]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u16; 29]

Source§

fn to_le_byte_vec(arr: [u16; 29]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u16; 30]

Source§

fn to_le_byte_vec(arr: [u16; 30]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u16; 31]

Source§

fn to_le_byte_vec(arr: [u16; 31]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u32; 2]

Source§

fn to_le_byte_vec(arr: [u32; 2]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u32; 4]

Source§

fn to_le_byte_vec(arr: [u32; 4]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u32; 6]

Source§

fn to_le_byte_vec(arr: [u32; 6]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u32; 14]

Source§

fn to_le_byte_vec(arr: [u32; 14]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u32; 15]

Source§

fn to_le_byte_vec(arr: [u32; 15]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u64; 4]

Source§

fn to_le_byte_vec(arr: [u64; 4]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Source§

impl ToBytes for [u64; 7]

Source§

fn to_le_byte_vec(arr: [u64; 7]) -> Vec<u8>

Source§

fn write_to_slice(self, target: &mut [u8])

Implementors§