Skip to content

Add rename support for derived atom names#728

Open
dannote wants to merge 2 commits into
rusterlium:masterfrom
dannote:rustler-rename-derive-fields
Open

Add rename support for derived atom names#728
dannote wants to merge 2 commits into
rusterlium:masterfrom
dannote:rustler-rename-derive-fields

Conversation

@dannote
Copy link
Copy Markdown
Contributor

@dannote dannote commented May 14, 2026

Adds #[rustler(rename = "...")] support for derive-generated atom names.

This lets Rust fields and enum variants keep valid Rust identifiers while encoding/decoding idiomatic Elixir keys like :type, :end, or :async.

Covered cases:

  • NifMap field names
  • NifTaggedEnum named fields
  • NifTaggedEnum variant tags

The rename parser rejects malformed rename attributes, and the tests cover both runtime behavior and invalid syntax.

Refs #727.

Tests run:

  • cargo test -q
  • cd rustler_tests && mix test test/codegen_test.exs

@filmor filmor force-pushed the rustler-rename-derive-fields branch from 568bd90 to ec22ca5 Compare May 15, 2026 20:31
Comment thread rustler_codegen/src/context.rs Outdated
fn atom_fun(atom_name: &str) -> Ident {
let suffix = atom_name
.chars()
.map(|c| if c.is_ascii_alphanumeric() { c } else { '_' })
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty aggressive and can fail with a confusing error in cases like name_ä vs name_ö. Wouldn't it make more sense to just fail with a proper error here? Apart from that, atoms can be at least latin1, on newer versions utf8.

@dannote dannote force-pushed the rustler-rename-derive-fields branch from ec22ca5 to b630cb3 Compare May 27, 2026 12:15
@dannote dannote force-pushed the rustler-rename-derive-fields branch from b630cb3 to 44586fe Compare May 27, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants