Skip to main content

Cheat Sheet

Type mapping#

This is a quick overview of the Encoder/Decoder implementation Rustler provides out of the box.

note

This is incomplete, contributions are welcome.

Rust TypeElixir TypeNotes
unsigned integer primitives (u8, u16, u32, u64)number 0..2^nDecoding will fail if number is out of range of primitive. Encoding will never fail.
signed integer primitives (i8, i16, i32, i64)number (n^2/2-1)..(n^2/2)Same as unsigned.
StringString.t()Decoding will perform UTF-8 validation of the full binary, will fail if binary is not valid UTF-8. Encoding will never fail. If more control is desired, you can work with the string as a Binary
Vec<T>list()List must be proper.
Vec<u8>[0..256]This is a special case of Vec<T>. If you want Vec<u8> to encode into a binary, you can either copy it into a OwnedBinary or make a wrapper struct with the correct encoder implementation.
rustler::Binary/rustler::OwnedBinarybinary()OwnedBinary is owned and mutable, Binary can be shared and is immutable.

Scenarios#