Skip to content

Commit

Permalink
Fix Nif* macros requiring an encoder (#676)
Browse files Browse the repository at this point in the history
* Fix Nif* macros requiring an encoder
* Add note and changelog entry
  • Loading branch information
filmor authored Jan 6, 2025
1 parent 6101dae commit 47ce1af
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
See [`UPGRADE.md`](./UPGRADE.md) for additional help when upgrading to newer
versions.

## unreleased

### Fixed

- Some derive macros failed when only `decode` was requested (#676)

## [0.35.1] - 2024-12-18

### Fixed
Expand Down
1 change: 0 additions & 1 deletion rustler_codegen/src/ex_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub fn transcoder_decorator(ast: &syn::DeriveInput, add_exception: bool) -> Toke

#decoder

#[allow(clippy::needless_borrow)]
#encoder
};

Expand Down
1 change: 0 additions & 1 deletion rustler_codegen/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub fn transcoder_decorator(ast: &syn::DeriveInput) -> TokenStream {

#decoder

#[allow(clippy::needless_borrow)]
#encoder
};

Expand Down
34 changes: 34 additions & 0 deletions rustler_tests/native/rustler_test/src/test_codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn tuple_echo(tuple: AddTuple) -> AddTuple {

#[derive(NifRecord)]
#[rustler(encode, decode)] // Added to check encode/decode attribute, #180
// The case of only `decode` is checked below
#[must_use] // Added to check attribute order (see similar issue #152)
#[tag = "record"]
pub struct AddRecord {
Expand Down Expand Up @@ -225,6 +226,39 @@ pub fn tuplestruct_record_echo(tuplestruct: TupleStructRecord) -> TupleStructRec
tuplestruct
}

mod check_if_only_decode_is_enough {
// Regression test, failed to compile
// TODO: Move this test to the trybuild tests in rustler_codegen

use rustler::{NifMap, NifRecord, NifStruct, NifTaggedEnum, NifTuple, NifUnitEnum};

#[derive(NifMap)]
#[rustler(decode)]
struct TestMap {}

#[derive(NifRecord)]
#[tag = "test_rec"]
#[rustler(decode)]
struct TestRec {}

#[derive(NifTuple)]
#[rustler(decode)]
struct TestTuple {}

#[derive(NifStruct)]
#[module = "TestStruct"]
#[rustler(decode)]
struct TestStruct {}

#[derive(NifUnitEnum)]
#[rustler(decode)]
enum TestUnitEnum {}

#[derive(NifTaggedEnum)]
#[rustler(decode)]
enum TestTaggedEnum {}
}

pub mod reserved_keywords {
use rustler::{NifMap, NifRecord, NifStruct, NifTuple, NifUntaggedEnum};

Expand Down

0 comments on commit 47ce1af

Please sign in to comment.