From 5a36a35bce0cc28e126564bcd19a2c3ff84bc82f Mon Sep 17 00:00:00 2001 From: Magnus Ottenklinger Date: Tue, 12 Nov 2019 19:40:20 +0100 Subject: [PATCH 1/4] Add changelog entries --- CHANGELOG.md | 60 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c79839b9..6f6196eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Support `CARGO_CFG_TARGET_POINTER_WIDTH`, enabling to compile rustler_sys for 32-bit systems +- Simple `Debug` impl for `rustler::Error` +- Support newtype and tuple structs for `NifTuple` and `NifRecord` +- `rustler::error::Term` encoding an arbitrary boxed encoder, returning `{:error, term}` + +### Fixed + +* Compilation time of generated decoders has been reduced significantly. + ### Changes - Renamed `Pid` to `LocalPid` to clarify that it can't point to a remote process @@ -18,26 +29,65 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `resource_struct_init!` is now `rustler::resource!` - New `rustler::atoms!` macro removed the `atom` prefix from the name: -```rs +```rust +// // Before - +// rustler::rustler_atoms! { atom ok; atom error; } +// // After - +// rustler::atoms! { ok, error, } ``` -### Fixed +- NIFs can be derived from regular functions, if the arguments implement `Decoder` and the return type implements `Encoder`: -* Compilation time of generated decoders has been reduced significantly. +```rust +// +// Before +// +fn add<'a>(env: Env<'a>, args: &[Term<'a>]) -> Result, 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 +} +``` + +- NIF functions can be initialized with a simplified syntax: + +```rust +// +// Before +// +rustler::rustler_export_nifs! { + "Elixir.Math", + [ + ("add", 2, add) + ], + None +} + +// +// After +// +rustler::init!("Elixir.Math", [add]); +``` ## [0.21.0] - 2019-09-07 From e1d0e441275013af6356a9e904046d6f3771902a Mon Sep 17 00:00:00 2001 From: Magnus Ottenklinger Date: Tue, 12 Nov 2019 21:03:42 +0100 Subject: [PATCH 2/4] Apply comments to changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f6196eb..8098d337 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Support `CARGO_CFG_TARGET_POINTER_WIDTH`, enabling to compile rustler_sys for 32-bit systems - Simple `Debug` impl for `rustler::Error` - Support newtype and tuple structs for `NifTuple` and `NifRecord` -- `rustler::error::Term` encoding an arbitrary boxed encoder, returning `{:error, term}` +- `rustler::Error::Term` encoding an arbitrary boxed encoder, returning `{:error, term}` ### Fixed From 0a91a7af5ccecb10d0afafb7a48912f5e340e9d4 Mon Sep 17 00:00:00 2001 From: Magnus Ottenklinger Date: Tue, 12 Nov 2019 21:07:59 +0100 Subject: [PATCH 3/4] Add attribute examples and reorder changelog --- CHANGELOG.md | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8098d337..abd4fb9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,26 @@ rustler::atoms! { } ``` +- NIF functions can be initialized with a simplified syntax: + +```rust +// +// 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 implements `Encoder`: ```rust @@ -68,24 +88,22 @@ fn add(a: i64, b: i64) -> i64 { } ``` -- NIF functions can be initialized with a simplified syntax: +- `rustler::nif` exposes more options to configure a NIF were the NIF is defined: ```rust -// -// Before -// -rustler::rustler_export_nifs! { - "Elixir.Math", - [ - ("add", 2, add) - ], - None + +#[rustler::nif(schedule = "DirtyCpu")] +pub fn dirty_cpu() -> Atom { + let duration = Duration::from_millis(100); + std::thread::sleep(duration); + + atoms::ok() } -// -// After -// -rustler::init!("Elixir.Math", [add]); +#[rustler::nif(name = "my_add")] +fn add(a: i64, b: i64) -> i64 { + a + b +} ``` ## [0.21.0] - 2019-09-07 From 453a98e345b11d039c4b3995ef6b6fe6564930d6 Mon Sep 17 00:00:00 2001 From: Magnus Ottenklinger Date: Mon, 6 Jan 2020 16:14:43 +0100 Subject: [PATCH 4/4] Mention fix for OwnedEnv::send_and_clear in CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abd4fb9c..c15bcd81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -* Compilation time of generated decoders has been reduced significantly. +- Compilation time of generated decoders has been reduced significantly. +- Fixed a segfault caused by `OwnedEnv::send_and_clear` ### Changes