Rustler v0.22.0 Release Notes
Release Date: 2019-09-07 // over 4 years ago-
โ Added
- Simple
Debug
impl forrustler::Error
- ๐ Support newtype and tuple structs for
NifTuple
andNifRecord
rustler::Error::Term
encoding an arbitrary boxed encoder, returning{:error, term}
- Generic encoder/decoder for
HashMap<T, U>
, whereT: Decoder
andU: Decoder
๐ Fixed
- Compilation time of generated decoders has been reduced significantly.
- Fixed a segfault caused by
OwnedEnv::send_and_clear
๐ Changes
- ๐ Renamed
Pid
toLocalPid
to clarify that it can't point to a remote process - โก๏ธ Dependencies have been updated.
- ๐จ Derive macros have been refactored.
- ๐ Macros have been renamed and old ones have been deprecated:
rustler_export_nifs!
is nowrustler::init!
rustler_atoms!
is nowrustler::atoms!
resource_struct_init!
is nowrustler::resource!
- ๐ New
rustler::atoms!
macro removed theatom
prefix from the name:
// // Before // rustler::rustler_atoms! { atom ok; atom error; atom renamed_atom = "Renamed"; } // // After // rustler::atoms! { ok, error, renamed_atom = "Renamed", }
- NIF functions can be initialized with a simplified syntax:
// // Before // rustler::rustler_export_nifs! { "Elixir.Math", [ ("add", 2, add) ], None } // // After // rustler::init!("Elixir.Math", [add]);
- NIFs can be derived from regular functions, if the arguments implement
Decoder
and the return type implementsEncoder
:
// // Before // fn add<'a>(env: Env<'a>, args: &[Term<'a>]) -> Result<Term<'a>, Error> { let num1: i64 = args[0].decode()?; let num2: i64 = args[1].decode()?; Ok((atoms::ok(), num1 + num2).encode(env)) } // // After // #[rustler::nif] fn add(a: i64, b: i64) -> i64 { a + b }
- ๐ง
rustler::nif
exposes more options to configure a NIF were the NIF is defined:
#[rustler::nif(schedule = "DirtyCpu")] pub fn dirty_cpu() -> Atom { let duration = Duration::from_millis(100); std::thread::sleep(duration); atoms::ok() } #[rustler::nif(name = "my_add")] fn add(a: i64, b: i64) -> i64 { a + b }
๐ Deprecations
๐ The rustler compiler has been deprecated and will be removed with v1.0. NIFs ๐ are no longer defined in
mix.exs
, but are configured withuse Rustler
. See ๐ the documentation for theRustler
module. To migrate to the new ๐ง configuration:- โฌ๏ธ Drop
:rustler
from the:compilers
key in yourmix.exs
project/0
function - โฌ๏ธ Drop
:rustler_crates
fromproject/0
and move the configurations into theuse Rustler
of your NIF module or application config:
# config/dev.exs config :my_app, MyApp.Native, mode: :debug
๐ For more information, see the documentation.
- Simple