Derive Macro rustler::NifMap

source ·
#[derive(NifMap)]
{
    // Attributes available to this derive:
    #[rustler]
}
Expand description

Derives implementations for the Encoder and Decoder traits which convert between Rust struct and an Elixir map.

For example, annotate the following struct:

#[derive(NifMap)]
struct AddMap {
    lhs: i32,
    rhs: i32,
}

Create a value of that type:

let value = AddMap { lhs: 33, rhs: 21 };

Then the traits Encoder and Decoder are derived automatically for your Rust struct such that encoding value would result in an elixir map with two elements like:

%{lhs: 33, rhs: 21}

And vice versa, decoding this map would result in value.