Comments (12)
With rust 2018 edition, macros can now be imported individually.
For example, you could do
mod a {
use strum_macros::Display;
#[derive(Display)]
enum UsesStrumDisplay {}
}
mod b {
use derive_more::Display;
#[derive(Display)]
enum UsesDeriveMoreDisplay {}
}
mod c {
use derive_more::Display;
use strum_macros::EnumString;
#[derive(Display, EnumString)]
enum UsesStrumEnumStringAndDeriveMoreDisplay {}
}
I've tested importing just FromEnum
and not Display
from strum_macros
and it works fine.
Could this issue be considered resolved?
from strum.
My only concern with
simply closing this issue is where distros with older versions of Rust are left -- I've been doing some research for the oldest supported distros, and pre-1.25 Rust distributions are still (unfortunately) fairly common. I have no idea what the proportion of users are that are actually ON those versions, but whatever the case it boils down to a question of the support policy this crate has. I don't see any mention of it in the README. Is there one?
And to be honest, I don't care if you take a minimal support policy and say "This crate should only be expected to work on the latest Rust." So long as it's a conscious decision, then users can at least have a definitive answer to any questions about the version of their toolchain in relation to strum
. :)
from strum.
My PR wholesale disables Display
, but renaming to indicate that the proc-macro comes from StrumDisplay
seems like an equally viable solution. I would personally prefer something like that to what I submitted -- simply omitting it was the simplest to implement at the time. :)
from strum.
Following up on this. The earliest version of rust right now that can compile strum is 1.26 because that's when impl trait was stabilized so I made a note on the README.
It's should be possible to rename macros with some conditional feature flags like we discussed above. I'm planning on creating one flag per custom derive because the overhead for adding a feature is so small, and typically the conflict only exists with a single name so consumers won't need to refactor their entire library, only colliding names.
Thanks for your patience on this. I've been busy with other things lately.
#[cfg_attr(not(feature = "verbose-enumstring-name"), proc_macro_derive(EnumString, attributes(strum)))]
#[cfg_attr(feature = "verbose-enumstring-name", proc_macro_derive(StrumEnumString, attributes(strum)))]
pub fn from_string(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let ast = syn::parse(input).unwrap();
let toks = from_string::from_string_inner(&ast);
debug_print_generated(&ast, &toks);
toks.into()
}
from strum.
Can we use more detailed name, such as EnumDisplay
?
I'm not sure whether it should be recommended rather than generic name Display
, or whether it should always be available.
But at least when Display
is disabled, such alternative name may be useful because it lets strum to avoid degrading its feature.
from strum.
@ErichDonGubler Thanks for the PR and being patient while I find time to look at it :)
@lo48576 Are you suggesting we change the name across the board or just when this feature flag is flipped? I wish I knew the roadmap for macros a better. To entirely future-proof this issue, we could just have a flag PrependStrum
that for all the derives puts strum in front of the attribute: StrumToString
, StrumDisplay
, etc. It's a little ugly for sure, but it would make it easy to avoid collisions across the whole crate.
from strum.
I meant renaming only Display
to some other name (and maybe also As{Static,Ref}str
).
It's because Display
and AsRefStr
is too generic and other crates may implement them for non-enum types.
In contrast, EnumString
and something like that is cleary for enum, and if other crates wanted to use that name, I think the feature is not provided by two crates for the same code.
For example, if both strum and other crate (call it alt_strum) provides derive(EnumDisplay)
, then users should not use them at the same time.
(It can happen, but it is not desirable to use two crates for same purpose, I think.
For such case, strum or alt_strum should cover all custom derives required by the user.)
To make strum future-proof (not only avoiding conflicts), using strum's own namespace (such as #[derive(Strum)] #[strum(derive(Display))]
) may be good.
from strum.
Just as a note, this is possible with Rust 2015 also -- I forget which release and I'm on mobile. Perhaps 1.30?
from strum.
@ErichDonGubler , I'm going to close this. Let me know if you disagree.
from strum.
@Peternator7: Haven't heard a response from this, just wanted to ping you.
from strum.
Hey @ErichDonGubler , thanks for following up on this. It had slipped my mind. That's interesting official distros are so old. Let me figure out what the earliest version of rustc compiles strum. I don't plan on having extensive long term support, but at least making sure new features don't break back compat is a good start. I'll get a travis build set up for that version.
from strum.
Housekeeping
This was implemented in 0.15.0
so I believe this issue is okay to close now.
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.