3 releases (1 stable)
1.0.0 | Dec 7, 2020 |
---|---|
0.1.1 | Dec 7, 2020 |
0.1.0 | Dec 7, 2020 |
#132 in #match
6KB
53 lines
is_variant
Generates methods to match enum variant.
Example
use is_variant::IsVariant;
#[derive(IsVariant)]
enum TestEnum {
A,
B(),
C(i32, i32),
D { _name: String, _age: i32 },
VariantTest,
}
fn main() {
let x = TestEnum::C(1, 2);
assert!(x.is_c());
let x = TestEnum::A;
assert!(x.is_a());
let x = TestEnum::B();
assert!(x.is_b());
let x = TestEnum::D {_name: "Jane Doe".into(), _age: 30 };
assert!(x.is_d());
let x = TestEnum::VariantTest;
assert!(x.is_variant_test());
}
lib.rs
:
Generates methods to match enum variant.
Example
use is_variant::IsVariant;
#[derive(IsVariant)]
enum TestEnum {
A,
B(),
C(i32, i32),
D { _name: String, _age: i32 },
VariantTest,
}
fn main() {
let x = TestEnum::C(1, 2);
assert!(x.is_c());
let x = TestEnum::A;
assert!(x.is_a());
let x = TestEnum::B();
assert!(x.is_b());
let x = TestEnum::D {_name: "Jane Doe".into(), _age: 30 };
assert!(x.is_d());
let x = TestEnum::VariantTest;
assert!(x.is_variant_test());
}
Dependencies
~1.5MB
~38K SLoC