rustler_stored_term

Crates.iorustler_stored_term
lib.rsrustler_stored_term
version0.1.0
sourcesrc
created_at2022-05-26 14:52:10.710281
updated_at2022-05-26 14:52:10.710281
descriptionStore arbitrary Elixir/Erlang terms inside any Rust datastructures you might be using inside your NIFs.
homepage
repositoryhttps://github.com/Qqwy/elixir-rustler_elixir_fun
max_upload_size
id594156
size8,504
Qqwy / Marten (Qqwy)

documentation

README

rustler_stored_term

When you implement a NIF (Natively Implemented Function) for Elixir/Erlang using Rust, you might at some point come across the situation where you want to persist Elixir/Erlang terms across multiple NIF calls.

For instance, you might want to store a bunch of them in a vector or some other collection for later use.

However, this is not easy to do in the general case: If you know for certain that a term passed to a NIF is e.g. a small integer or a string, you can convert it to that particular datatype. But many datatypes (functions, references, ports, big integers, etc.) can not safely be converted on the Rust side at all. And the terms passed to any individual NIF call are limited by their lifetime to this particular call.

This library allows to keep them longer, by converting them to a stable format. 'Known' datatypes are converted to simple Rust equivalents, and the rest is handled by copying the term to a Rustler OwnedEnv (c.f. TermBox).

Conversion between Terms and StoredTerms is very simple, as it implements Rustlers' Encoder/Decoder traits.

Commit count: 44

cargo fmt