#step #stable #macro-derive #stable-step

过程宏 stable-step-derive

稳定Rust的Step实现(派生宏)

1个不稳定版本

0.1.0 2022年1月14日

#101 in #step


用于 stable-step

Apache-2.0/MIT

4KB
77

stable-step

稳定Rust中的步骤

示例

无依赖

[dependencies]
stable-step = "0.1"
use stable_step::{Step, StepExt};

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
enum MyEnum {
    A,
    B,
}

impl Step for MyEnum {
    const MIN: Self = Self::A;
    const MAX: Self = Self::B;

    fn next(&self) -> Option<Self> {
        match self {
            Self::A => Some(Self::B),
            _ => None,
        }
    }

    fn prev(&self) -> Option<Self> {
        match self {
            Self::B => Some(Self::A),
            _ => None,
        }
    }
}

fn main() {
    for value in MyEnum::iter() {
        println!("{:?}", value);
    }
}

过程宏

[dependencies]
stable-step = { version = "0.1", features = ["derive"] }
use stable_step::{Step, StepExt};

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Step)]
enum MyEnum {
    A,
    B,
}

fn main() {
    for value in MyEnum::iter() {
        println!("{:?}", value);
    }
}

许可证

许可协议为Apache License,版本2.0或MIT许可证,您可选择其一。
除非您明确指出,否则您有意提交的任何贡献,根据Apache-2.0许可证的定义,都应按照上述方式双许可,不附加任何额外条款或条件。

依赖项

~1.5MB
~35K SLoC