Add rename support for derived atom names#728
Open
dannote wants to merge 2 commits into
Open
Conversation
568bd90 to
ec22ca5
Compare
filmor
reviewed
May 23, 2026
| fn atom_fun(atom_name: &str) -> Ident { | ||
| let suffix = atom_name | ||
| .chars() | ||
| .map(|c| if c.is_ascii_alphanumeric() { c } else { '_' }) |
Member
There was a problem hiding this comment.
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.
ec22ca5 to
b630cb3
Compare
b630cb3 to
44586fe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
NifMapfield namesNifTaggedEnumnamed fieldsNifTaggedEnumvariant tagsThe rename parser rejects malformed rename attributes, and the tests cover both runtime behavior and invalid syntax.
Refs #727.
Tests run:
cargo test -qcd rustler_tests && mix test test/codegen_test.exs