Skip to content

Conversation

@LafCorentin
Copy link

Hi

I needed to iterate over en enum's default variant, so I added a option to enum-iterator.

If you prefer other terms or structure I would be glad to adapt.

All tests are good.

@stephaneyfx
Copy link
Owner

Hi @LafCorentin,

Thank you for opening this PR and I apologize for the late response.

May you share your concrete use case where only default values are needed for variants with fields?

Does that do what you want?

@LafCorentin
Copy link
Author

This is about representing a menu. the value is changed for the previous or following one, cycling both way. With your crate I have the cardinal of the the enum sizing my menu, access to the last one to cycle in reverse, and it can iterate both way endlessly without consuming anything. I don't feel like the other iterator is made for that.
But yeah I'm bringing their approach with my option.

@stephaneyfx
Copy link
Owner

Let's assume that the menu represents the Action enum defined below:

use enum_iterator::Sequence;

#[derive(Clone, Copy, Default, Sequence)]
enum Size {
    Small,
    #[default]
    Medium,
    Large,
}

#[derive(Clone, Copy, Sequence)]
enum Action {
    Insert,
    Size(Size),
    Delete,
}

What items are expected in the menu? I would expect the following:

  • Insert
  • Size(Small)
  • Size(Medium)
  • Size(Large)
  • Delete

If I understand this PR correctly, the menu would instead look as follows:

  • Insert
  • Size(Medium)
  • Delete

Why are other sizes ignored? I am trying to understand the rationale for considering only default values of variant fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants