pub trait Serial {
    fn serial<W>(&self, _out: &mut W) -> Result<(), <W as Write>::Err>
    where
        W: Write
; }
Expand description

The Serial trait provides a means of writing structures into byte-sinks (Write).

Can be derived using #[derive(Serial)] for most cases.

Required Methods

Attempt to write the structure into the provided writer, failing if only part of the structure could be written.

NB: We use Result instead of Option for better composability with other constructs.

Implementations on Foreign Types

Serialized if the Option is a None we write 0u8. If Some, we write 1u8 followed by the serialization of the contained T.

Serialization of bool encodes it as a single byte, false is represented by 0u8 and true is only represented by 1u8.

The serialization of maps encodes their size as a u32. This should be sufficient for all realistic use cases in smart contracts. They are serialized in no particular order.

Serialize the array by writing elements consecutively starting at 0. Since the length of the array is known statically it is not written out explicitly. Thus serialization of the array A and the slice &A[..] differ.

Serialized by writing an u32 representing the number of bytes for a utf8-encoding of the string, then writing the bytes. Similar to Vec<_>.

sufficient for all realistic use cases in smart contracts. They are serialized in no particular order.

Implementors

Serialized by writing an u32 representing the number of bytes for a utf8-encoding of the string, then writing the bytes. Similar to &str.

The serialization of sets encodes their size as a u32. This should be sufficient for all realistic use cases in smart contracts. They are serialized in canonical order (increasing)

The serialization of maps encodes their size as a u32. This should be sufficient for all realistic use cases in smart contracts. They are serialized in ascending order.

Serialized by writing an u32 representing the number of elements, followed by the elements serialized according to their type T.