Trait tinkerforge::byte_converter::ToBytes
source · pub trait ToBytes {
fn to_le_bytes(_: Self) -> Vec<u8>;
fn try_to_le_bytes(
var: Self,
_max_len: usize
) -> Result<Vec<u8>, BrickletError>
where
Self: Sized,
{ ... }
}
Expand description
A trait to serialize the implementing type to a byte vector.
Required Methods
sourcefn to_le_bytes(_: Self) -> Vec<u8>
fn to_le_bytes(_: Self) -> Vec<u8>
Serialize the implementing type to a byte vector.
Provided Methods
sourcefn try_to_le_bytes(var: Self, _max_len: usize) -> Result<Vec<u8>, BrickletError>where
Self: Sized,
fn try_to_le_bytes(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_bytes
without further checks or padding.
Errors
Returns an InvalidArgument error if the type was too long.