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,

Object Safety§

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§