Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stephaneyfx/enum-iterator
Tools to iterate over all values of a type
https://github.com/stephaneyfx/enum-iterator
Last synced: 3 months ago
JSON representation
Tools to iterate over all values of a type
- Host: GitHub
- URL: https://github.com/stephaneyfx/enum-iterator
- Owner: stephaneyfx
- License: 0bsd
- Created: 2018-07-02T22:06:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-01T05:26:47.000Z (7 months ago)
- Last Synced: 2024-06-19T23:29:25.511Z (5 months ago)
- Language: Rust
- Homepage:
- Size: 73.2 KB
- Stars: 97
- Watchers: 5
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Overview
- [📦 crates.io](https://crates.io/crates/enum-iterator)
- [📖 Documentation](https://docs.rs/enum-iterator)
- [âš– 0BSD license](https://spdx.org/licenses/0BSD.html)Tools to iterate over the values of a type.
# Examples
```rust
use enum_iterator::{all, cardinality, first, last, next, previous, reverse_all, Sequence};#[derive(Debug, PartialEq, Sequence)]
enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }assert_eq!(cardinality::(), 7);
assert_eq!(all::().collect::>(), [
Day::Monday,
Day::Tuesday,
Day::Wednesday,
Day::Thursday,
Day::Friday,
Day::Saturday,
Day::Sunday,
]);
assert_eq!(first::(), Some(Day::Monday));
assert_eq!(last::(), Some(Day::Sunday));
assert_eq!(next(&Day::Tuesday), Some(Day::Wednesday));
assert_eq!(previous(&Day::Wednesday), Some(Day::Tuesday));
assert_eq!(reverse_all::().collect::>(), [
Day::Sunday,
Day::Saturday,
Day::Friday,
Day::Thursday,
Day::Wednesday,
Day::Tuesday,
Day::Monday,
]);
``````rust
use enum_iterator::{cardinality, first, last, Sequence};#[derive(Debug, PartialEq, Sequence)]
struct Foo {
a: bool,
b: u8,
}assert_eq!(cardinality::(), 512);
assert_eq!(first::(), Some(Foo { a: false, b: 0 }));
assert_eq!(last::(), Some(Foo { a: true, b: 255 }));
```# Rust version
This crate tracks stable Rust. Minor releases may require a newer Rust version. Patch releases
must not require a newer Rust version.# Contribute
All contributions shall be licensed under the [0BSD license](https://spdx.org/licenses/0BSD.html).