pub trait Serial {
    fn serial<W: Write>(&self, _out: &mut W) -> Result<(), W::Err>;
}
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

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

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

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

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

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

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.

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)

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.

Implementors

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

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.