Trait tinkerforge_async::byte_converter::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§
sourcefn to_le_byte_vec(_: Self) -> Vec<u8>
fn to_le_byte_vec(_: Self) -> Vec<u8>
Serialize the implementing type to a byte vector.
fn write_to_slice(self, target: &mut [u8])
Provided Methods§
sourcefn try_to_le_byte_vec(
var: Self,
_max_len: usize
) -> Result<Vec<u8>, BrickletError>where
Self: Sized,
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.
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.