Code Monkey home page Code Monkey logo

enum-kinds's People

Contributors

antifuchs avatar soft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

enum-kinds's Issues

Allow changing visibility of derived enum

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

Kind trait?

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.

Copying Over Enum Variant Documentation

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.

cargo clippy warns on unused lifetime

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 macro EnumKind (in Nightly builds, run with -Z macro-backtrace for more info)

How to add per-variant attribute?

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.