Serde Serializer and Deserializer traits for Rustler NIFs.
serde_rustler
provides Serde Serializer and Deserializer traits for Rustler types, so you can easily serialize and deserialize native Rust types directly to and from native Elixir terms within your NIFs.
Install from Crates.io:
toml
[dependencies]
serde_rustler = "0.0.1"
rust
| Type Name | Serde Data Model | Default Elixir Term |
|-----------|------------------|---------------------|
| bool | true
or false
| true
or false
|
| number | i8
, i16
, i32
, i64
, u8
, u16
, u32
, u64
, f32
, f64
| number
|
| char | ""
| bitstring
|
| string | ""
| bitstring
|
| byte array | [u8]
| <<_::_*8>>
|
| option | Some(T)
or None
| T
or :nil
|
| unit | None
| :nil
|
| unit struct | struct Unit
| :nil
|
| unit variant | E::A
in enum UnitVariant { A }
| *:A
|
| newtype struct | struct Millimeters(u8)
| 1{:Millimeters, u8}
|
| newtype variant | E::N
in enum E { N(u8) }
| 1{:N, u8}
|
| seq | Vec<T>
| [T]
|
| tuple | (u8,)
| {u8,}
|
| tuple struct | struct Rgb(u8, u8, u8)
| 1{:Rgb, u8, u8, u8}
|
| tuple variant | E::T
in enum E { T(u8, u8) }
| 1{:T, u8, u8}
|
| map | HashMap<K, V>
| %{}
|
| struct | struct Rgb { r: u8, g: u8, b: u8 }
| 1%Rgb{ r: byte, g: byte, b: byte }
|
| struct variant | E::S
in enum E { Rgb { r: u8, g: u8, b: u8 } }
| 1%Rgb{ r: byte, g: byte, b: byte }
|
1: If transcoding, the atom may not exist and will instead be serialized/deserialized to/from an Elixir bitstring. This means that may only be maps with a __struct__
key and string value. These types are also lossy (newtype structs and variants are indistinguishable in Elixir terms), so deserialization hints may be required.
| Version | Change Summary | | ------- | ---------------| | v0.0.1 | initial release |
git checkout -b feature/fooBar
)git commit -am 'Add some fooBar'
)git push origin feature/fooBar
)MIT