pub trait Serial {
    // Required method
    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§

source

fn serial<W>(&self, _out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Serial for &str

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

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for bool

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

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for i8

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for i16

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for i32

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for i64

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for i128

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for u8

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for u16

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for u32

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for u64

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for u128

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl Serial for ()

source§

fn serial<W>(&self, _out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl<A> Serial for &A
where A: Serial,

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl<A, B> Serial for (A, B)
where A: Serial, B: Serial,

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl<A, B, C> Serial for (A, B, C)
where A: Serial, B: Serial, C: Serial,

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl<A, B, C, D> Serial for (A, B, C, D)
where A: Serial, B: Serial, C: Serial, D: Serial,

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl<A, B, C, D, E> Serial for (A, B, C, D, E)
where A: Serial, B: Serial, C: Serial, D: Serial, E: Serial,

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl<A, B, C, D, E, F> Serial for (A, B, C, D, E, F)
where A: Serial, B: Serial, C: Serial, D: Serial, E: Serial, F: Serial,

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl<K> Serial for HashSet<K, BuildHasherDefault<FnvHasher>>
where K: Serial,

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

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl<K, V> Serial for HashMap<K, V, BuildHasherDefault<FnvHasher>>
where K: Serial, V: Serial,

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.

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl<T> Serial for Option<T>
where T: Serial,

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

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

source§

impl<T, const N: usize> Serial for [T; N]
where T: Serial,

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.

source§

fn serial<W>(&self, out: &mut W) -> Result<(), <W as Write>::Err>
where W: Write,

Implementors§

source§

impl Serial for Address

source§

impl Serial for PublicKey

source§

impl Serial for Signature

source§

impl Serial for Fields

source§

impl Serial for FunctionV1

source§

impl Serial for SizeLength

source§

impl Serial for Type

source§

impl Serial for VersionedModuleSchema

source§

impl Serial for ContractV0

source§

impl Serial for ContractV1

source§

impl Serial for ContractV2

source§

impl Serial for ContractV3

source§

impl Serial for FunctionV2

source§

impl Serial for ModuleV0

source§

impl Serial for ModuleV1

source§

impl Serial for ModuleV2

source§

impl Serial for ModuleV3

source§

impl Serial for AccountAddress

source§

impl Serial for AccountBalance

source§

impl Serial for AccountPublicKeys

source§

impl Serial for AccountSignatures

source§

impl Serial for Amount

source§

impl Serial for AttributeTag

source§

impl Serial for AttributeValue

source§

impl Serial for ChainMetadata

source§

impl Serial for ContractAddress

source§

impl Serial for CredentialPublicKeys

source§

impl Serial for CredentialSignatures

source§

impl Serial for Duration

source§

impl Serial for ExchangeRate

source§

impl Serial for ExchangeRates

source§

impl Serial for HashKeccak256

source§

impl Serial for HashSha2256

source§

impl Serial for HashSha3256

source§

impl Serial for MetadataUrl

source§

impl Serial for OwnedContractName

source§

impl Serial for OwnedEntrypointName

source§

impl Serial for OwnedParameter

source§

impl Serial for OwnedReceiveName

source§

impl Serial for Policy<Vec<(AttributeTag, AttributeValue)>>

source§

impl Serial for PublicKeyEcdsaSecp256k1

source§

impl Serial for PublicKeyEd25519

source§

impl Serial for SignatureEcdsaSecp256k1

source§

impl Serial for SignatureEd25519

source§

impl Serial for String

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

source§

impl Serial for Timestamp

source§

impl<'a> Serial for ContractName<'a>

source§

impl<'a> Serial for EntrypointName<'a>

source§

impl<'a> Serial for Parameter<'a>

source§

impl<'a> Serial for ReceiveName<'a>

source§

impl<C> Serial for PhantomData<C>
where C: ?Sized,

source§

impl<K> Serial for BTreeSet<K>
where K: Serial + Ord,

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)

source§

impl<K, V> Serial for BTreeMap<K, V>
where K: Serial + Ord, V: Serial,

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.

source§

impl<K, V, S> Serial for StateMap<K, V, S>

source§

impl<K, V, const M: usize> Serial for StateBTreeMap<K, V, M>
where K: Serial, V: Serial,

source§

impl<Kind> Serial for NonZeroThresholdU8<Kind>

source§

impl<Purpose> Serial for HashBytes<Purpose>

source§

impl<T> Serial for Box<T>
where T: Serial,

source§

impl<T> Serial for Vec<T>
where T: Serial,

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

source§

impl<T, S> Serial for StateSet<T, S>

source§

impl<T: Serial, S: HasStateApi> Serial for StateBox<T, S>

source§

impl<const M: usize, K> Serial for StateBTreeSet<K, M>