soft / enum-kinds Goto Github PK
View Code? Open in Web Editor NEWGenerate enums with matching variants, but without any of the associated data.
Home Page: https://docs.rs/enum-kinds-macros
Generate enums with matching variants, but without any of the associated data.
Home Page: https://docs.rs/enum-kinds-macros
Hi,
thanks for the very handy trait.
Would you consider providing a trait, e.g. something like this:
trait Kind {
type Kind;
fn kind() -> Self::Kind
}
This would enable building more generic / reusable code.
For example, in my particular case, I have functions to detect values of duplicated kinds.
I'm getting the following warning when used with cargo clippy:
warning: this lifetime isn't used in the impl
--> src/options.rs:6:39
|
6 | #[derive(Clone, PartialEq, Eq, Debug, EnumKind)]
| ^^^^^^^^
|
= note:#[warn(clippy::extra_unused_lifetimes)]
on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
= note: this warning originates in the derive macroEnumKind
(in Nightly builds, run with -Z macro-backtrace for more info)
I'd like to have a private enum as an implementation detail of my library, but provide a public method (on another type) that returns its kind. However, it seems enum-kinds always copies the visibility of the original enum.
For example:
#[derive(EnumKind)]
#[enum_kind(FooKind)]
enum Foo {
A(u32),
B(u64),
}
pub fn get_a_foo() -> FooKind {
Foo::A(0).into()
}
This produces:
error[E0446]: private type `FooKind` in public interface
--> src/lib.rs:36:1
|
29 | #[derive(EnumKind)]
| -------- `FooKind` declared as private
...
36 | pub fn get_a_foo() -> FooKind {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't leak private type
Is it possible to use the generated enum in a different crate?
I want to derive Default
for my custom enum. To do this, I'd like to write this:
#[derive(EnumKind)]
#[enum_kind(PainterKind, derive(Default))]
pub enum Painter {
#[default]
LinePainter,
CirclePainter,
}
But that #[default]
attribute is not on PainterKind
, but on Painter
. Can we add support for such derives?
Would it be possible to copy over enum variant documentation to the EnumKind
?
It's not a huge issue by any means, but I feel it would make the derived enum feel a little more polished in a public API.
It could even just be an optional behaviour.
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.