Macro exonum::encoding_struct [] [src]

macro_rules! encoding_struct {
    (
    $(#[$attr:meta])*
    struct $name:ident {
        $(
        $(#[$field_attr:meta])*
        $field_name:ident : $field_type:ty
        ),*
        $(,)*
    }) => { ... };
}

encoding_struct! macro implements a structure that can be saved in the Exonum blockchain.

The macro creates getter methods for all fields with the same names as fields. In addition, the macro declares a new constructor, which accepts all fields in the order of their declaration in the macro. The macro also implements Field, ExonumJson and StorageValue traits for the declared datatype.

Unlike types created with message!, the datatype is mapped to a byte buffer without any checks; it is assumed that the relevant checks have been performed when persisting the structure to the blockchain storage.

For additional reference about data layout see the documentation of the encoding module.

NB. encoding_struct! uses other macros in the exonum crate internally. Be sure to add them to the global scope.

Examples

#[macro_use] extern crate exonum;

encoding_struct! {
    struct SaveTwoIntegers {
        first: u64,
        second: u64,
    }
}

let s = SaveTwoIntegers::new(1, 2);
println!("Two integers: {:?}", s);