ecstatic-morse / enum-utils Goto Github PK
View Code? Open in Web Editor NEWA set of useful proc macros for enums
A set of useful proc macros for enums
It appears that the IterVariants
derive will only produce a private fn iter()
which makes it only useful in the module where the enum is defined. I'd like to see a way to override this:
pub mod foo {
#[derive(enum_utils::IterVariants)]
// well-behaved attributes are namespaced
// also so you only have to declare the `enum_utils` attribute in `#[proc_macro_derive]`
#[enum_utils(iter(visibility = "pub"))]
pub enum Foo {
Bar,
Baz
}
}
fn main() {
let variants = foo::Foo::iter();
}
Additionally, it might be nice to override the generated method name:
#[derive(enum_utils::IterVariants)]
#[enum_utils(iter(name = "variants"))]
enum Foo {
Bar,
Baz
}
fn main() {
let variants = Foo::variants();
}
This exists in strum
and derive-more
but the former is complicated and the latter doesn't have FromStr
or TryFrom<{repr}>
derives for enums. I rather like the simplicity and narrowed scope of this crate and it'd be nice not to have to import multiple crates to get all the derives I need. I'd be glad to open a PR if you'd accept it.
I want to use this in conjunction with structopt, whose derive macro expands to this:
.validator(|s| {
::std::str::FromStr::from_str(s.as_str())
.map(|_: Eval| ())
.map_err(|e| e.to_string())
})
Obviously this won't work as the default error type ()
doesn't implement Display
.
Last available version of the repository on crates.io is 0.1.1, however the building of the version is terminated with compilation error. Currently master branch is ok. Could you to update package on crates.io?
I tested on two different platforms and the result is the same:
stable-x86_64-unknown-linux-gnu (default)
rustc 1.38.0 (625451e37 2019-09-23)
nightly-armv7-unknown-linux-gnueabihf (default)
rustc 1.40.0-nightly (6767d9b90 2019-10-11)
P.S. It would be nice to push git tags for all releases.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.