All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
See UPGRADE.md
for additional help when upgrading to newer versions.
ErlOption<T>
to provide an ergonomic option type for Erlang (#507, thanks @tatsuya6502)
- Use Cargo features to define the NIF version level (#537), deprecating
RUSTLER_NIF_VERSION
- Support OTP 26 (#526, thanks @philss)
- Support tuples in NIF macro (#520, #527, thanks @denumerate and @philss)
- Supportfor
load_data_fun
to computeload_data
at runtime (#413, thanks @kaaboaye)
- Enhanced NIF macro error messages for invalid attributes (#525, thanks @philss)
MIX_ENV
is no longer considered for determining the build profile. Now, the profile defaults to:release
. Use the:mode
option to pick another profile explicitly. (#496)
ResourceArc::make_binary
for safe use ofenif_make_resource_binary
(#487)OwnedBinary
is nowSync
(#493)- Specified MSRV to be 1.56.1.
- Documentation for
load
(#501, thanks @ishitatsuyuki)
- Edition 2021 for the rustler mix template (#512, thanks @ayrat555)
We added TaggedEnum
, which is a generalized enum type (#440, thanks to @SeokminHong!). Example:
#[derive(NifTaggedEnum)]
pub enum TaggedEnum1 {
Named { x: i32, y: i32 },
String1(String),
String2(String),
Untagged,
}
On the Elixir side, the variants are represented as two-tuples {tag::atom(), inner::term()} | atom()
, where the inner
term is
- a map for the variant
Named
in the example above - a binary for the
String1
andString2
variants
The Untagged
variant is represented as the atom :untagged
in Elixir.
- Added
Clone
andCopy
forTermType
(#476, thanks @dvic) - Added
Env.whereis_pid()
(#456, thanks @Qqwy)
- Use
&[impl Encoder]
for keys and values inmap_from_arrays()
to improve ergonomics (#453, thanks @SeokminHong) - Improved encode/decode performance of TaggedEnum considerably (#482, thanks @cleaton)
- Test on OTP 25 (#455)
- Lifetime handling in
rustler_codegen
(#483, thanks @turion @SeokminHong and @neosimsim) - Support multiple variants with same field names in TaggedEnum (#482, thanks @cleaton)
- Support .toml file extension for cargo config (#468, thanks @joshuataylor for the report in #467)
- Disambiguate
encode
/decode
in generated code (#466, thanks @SeokminHong) - Migrate CI to
erlef/setup-beam
(#457, thanks @SeokminHong) - Documentation of the
schedule
flag fornif
macro (#444) - Improve documentation (#429, thanks @turion)
NewBinary
now also available asrustler::NewBinary
(thanks @ayrat555)Term::map_from_pairs()
to conveniently build a map from a list -of pairs (thanks @philss)- CI now also tests against macos
- Snake-case warening for auto-generated
RUSTLER_{}_field_{}
variables (renamed torustler_{}_field_{}
)
- Abort compilation on macos if macos target configuration is missing
- A
NewBinary
type to create binaries in Rust without going throughOwnedBinary
. This can improve performance. Thanks @dlesl! TermType
derivesEq
andPartialEq
.
rustler_mix
: Bumped required toml dependency to 0.6- Bumped
rustler_sys
dependency to~2.2
.
- Rustler supports the latest 3 versions of Elixir and OTP. Currently, those are Elixir => 1.11 and OTP >= 22.
- Set library file extension based on the compile target, thanks @cocoa-xu!
- Relaxed Jason version requirement to ~> 1.0
- Various typos in the documentation, thanks @kianmeng!
NifException
for using Elixir exception structs- Hashing for term
- Hash and Equality for
Binary
andOwnedBinary
- Rustler changed its supported range of OTP and Elixir versions. We aim to support the three newest versions of OTP and Elixir.
- The decoder for
Range
requires that:step
equals1
. The:step
field was introduced with Elixir v1.12 and cannot be represented with Rust'sRangeInclusive
. - NIF API bindings are generated using Rust
mix rustler.new
with Elixir v1.13- Template config for
macos
- Crash if metadata cannot be retrieved while compiling (#398)
- Fixed a regression introduced with #386:
Rustler.Compiler.Config
called intocargo
whenskip_compilation?
was set, breaking setups where cargo is not installed. Fixed with #389, thanks @karolsluszniak
- [Breaking change] codegen-generated decoders always raise an error instead of causing the calling NIF to return an atom in some cases
- Fix codegen problem for untagged enums (#370)
- Fix handling local dependencies with
@external_resources
(#381)
- 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
- Compilation time of generated decoders has been reduced significantly.
- Fixed a segfault caused by
OwnedEnv::send_and_clear
- 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
}
The rustler compiler has been deprecated and will be removed with v1.0. NIFs
are no longer defined in mix.exs
, but are configured with use Rustler
. See
the documentation for the Rustler
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.
- Support for OTP22.
- Rust linting with clippy.
- Support for decoding IOLists as binaries,
Term::decode_as_binary
.
rustler_codegen
is now reexported by therustler
crate. Depending on therustler_codegen
crate is deprecated.erlang_nif-sys
has been renamed torustler_sys
and vendored into the rustler repo.- Replaced the hand-rolled TOML parser in
rustler_mix
with thetoml-elixir
package. - Improve error messages for derived encoders/decoders.
- Rust
bool
now corresponds only to booleans (false
,true
) in Elixir. Previously,nil
andfalse
were both decodable tobool
. To use the previous behaviour, aTruthy
newtype was introduced.