Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attribute keep_case for NifUnitEnum #263

Open
evnu opened this issue Oct 23, 2019 · 7 comments
Open

Add attribute keep_case for NifUnitEnum #263

evnu opened this issue Oct 23, 2019 · 7 comments

Comments

@evnu
Copy link
Member

evnu commented Oct 23, 2019

NifUnitEnum currently expects atoms corresponding to struct fields to be in snake case. This works fine when the user can define the atoms to be in snake case. If that is not possible, e.g. because they are defined by a third party, then decoding them with NifUnitEnum is not possible.

I suggest we add an attribute keep_case which defines that the fields are to be used exactly as-is as atoms.

#[derive(NifUnitEnum)]
#[rustler(keep_case)]
pub struct KeepCase {
  UPPERCASE,
  lowercase
}
@scrogson
Copy link
Member

scrogson commented Oct 24, 2019

What about something more similar to serde's rename?

#[derive(NifUnitEnum)]
pub struct KeepCase {
    #[rustler(rename = "UPPERCASE")]
    uppercase,
    lowercase
}

I imagine that if we end up adding serde support to rustler, we will end up just using #[serde(rename = "UPPERCASE")] ?

@evnu
Copy link
Member Author

evnu commented Oct 24, 2019

What about something more similar to serde's rename?

Yes, that would work. Does serde by default rename variants at all, or does it keep them as-is except when rename is specified?

@filmor
Copy link
Member

filmor commented Oct 25, 2019

Wouldn't it make sense to instead work on getting serde_rustler in? I don't see the advantage of a custom codegen right now.

@evnu
Copy link
Member Author

evnu commented Oct 25, 2019

As this is a small change, I would do this. I am unsure how much work serde_rustler will be. Of course, rustler_serde would be the preferred way.

@scrogson
Copy link
Member

Of course, rustler_serde would be the preferred way.

Agreed in the context of this crate. I would assume that it wouldn't really be useful outside of rustler anyways.

@sunny-g
Copy link
Contributor

sunny-g commented Mar 5, 2020

Mentioned here:

Depending on how willing y'all are to change up rustler and depend directly on serde, a lot of ser/de + encoder/decoder + macro logic could be simplified and/or gotten rid of. The simplest non-breaking change however would be to just copy my Serializer and Deserializer logic and implement them directly on Env and Term respectively behind a feature flag, no real need for a separate crate.

@scrogson
Copy link
Member

scrogson commented Mar 9, 2020

I started working on integrating this into rustler over the weekend 👍

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

No branches or pull requests

4 participants