#enums #iterable #proc-macro #derive #macro

macro case_iterable

A procedural macro to iterate over enum variants, ala Swift's CaseIterable

2 unstable releases

0.2.0 Oct 4, 2024
0.1.0 Oct 3, 2024

#865 in Rust patterns

Download history 349/week @ 2024-10-02 30/week @ 2024-10-09 14/week @ 2024-10-16

393 downloads per month

GPL-3.0 license

17KB
256 lines

case_iterable

License: GPL v3 Crates.io

Installation

case_iterable can be installed with cargo:

$ cargo add case_iterable

or by manually adding it to your Cargo.toml:

[dependencies]
case_iterable = "0.2.0"

Usage

use case_iterable::CaseIterable;

#[derive(CaseIterable)]
enum Foo {
    A,
    Bar,
    Chocolate,
}

for variant in Foo::all_cases() {
    // Foo::A
    // Foo::Bar
    // Foo::Chocolate
}

// also exposes the next function used for the iterator
let x = Foo::Bar;
let y = x.next();  // Some(Foo::Chocolate)

License

Licensed under GNU General Public License, Version 3.0 This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Dependencies

~245–700KB
~17K SLoC