Comments (5)
That's a good idea, and it shouldn't be too hard to add a ToString
implementation. I might be able to get to it this weekend.
The rename
and alias
feature mostly already exists in the form of serialize
. It would be nice to have some way of identifying the preferred serialization though. I'll think about this as well.
from strum.
Oh great 👍 I'll watch for this as I prefer to have a single library doing this instead of rolling it by myself n-times.
I've read about the multi-entry serialize
, but here you need some kind of "leader-selection" to string-ify. rename
comes from serde while alias
it's just a random suggestion of mine. Feel free to pick whatever you think suits better, I'd just like to be able to have a single field for both ToString and FromString.
from strum.
Hey @lucab,
I merged changes into master. I couldn't find a keyword I was in love with; I wanted to stay in the spirit of serialize
, but nothing felt super good so I settled on to_string="..."
The updated docs explain how it works, but here's the short version. FromString
will include both serialize
and to_string
(a bit confusing I know) when it's attempting to parse a string. ToString
will prefer to_string
if it is present when converting an enum into a string.
from strum.
Thanks, I'll give 0.6.0 a try.
from strum.
Adopted in camallo/dkregistry-rs#17, this suits what I was looking for. Closing.
from strum.
Related Issues (20)
- derive(FromRepr) broken in 0.25.0 HOT 13
- Unwrap methods HOT 6
- strum(serialize_all vs serde(rename_all HOT 1
- rustfmt::skip is broken by derive(FromRepr) HOT 1
- Maybe EnumCount should respect `#[repr(...)]` like FromRepr HOT 2
- EnumDiscriminants should inherit the repr of the enum they are derived from HOT 1
- `could not find fmt in core` when upgrading to 0.25 HOT 1
- Proposal: Exclude macro for EnumIter macro
- IntoStaticStr but from immutable reference to an enum From<&MyEnum> HOT 7
- `EnumString` match with non-default variables HOT 1
- Feature request: A function to convert to integer by variant HOT 1
- EnumIter does not work for enums named 'Option'
- [Feature] Macro to Implement PartialEq<str> HOT 1
- strum::Display doesn't work with non-unit non-string variants
- `EnumString` should derive `From<&str>` instead of `TryFrom<&str>` when `#[strum(default)]` is present HOT 1
- to_string and serialize when used together causes unreachable code HOT 2
- `get_bool` and `get_int` in `EnumProperty` are undocumented and always return None
- AsRef<str> and default variants
- EnumDiscriminants: can't infer type HOT 3
- Getting the discriminant from an enum variant HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strum.