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

Serialize the implementing type to a byte vector.

Provided Methods

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.

Implementations on Foreign Types

Implementors