1 个不稳定版本

0.1.0 2022年9月7日

#16#variant-name

Download history • Rust 包仓库 20/week @ 2024-04-17 • Rust 包仓库 28/week @ 2024-04-24 • Rust 包仓库 59/week @ 2024-05-01 • Rust 包仓库 47/week @ 2024-05-08 • Rust 包仓库 40/week @ 2024-05-15 • Rust 包仓库 63/week @ 2024-05-22 • Rust 包仓库 56/week @ 2024-05-29 • Rust 包仓库 46/week @ 2024-06-05 • Rust 包仓库 34/week @ 2024-06-12 • Rust 包仓库 62/week @ 2024-06-19 • Rust 包仓库 44/week @ 2024-06-26 • Rust 包仓库 5/week @ 2024-07-03 • Rust 包仓库 36/week @ 2024-07-10 • Rust 包仓库 105/week @ 2024-07-17 • Rust 包仓库 72/week @ 2024-07-24 • Rust 包仓库 55/week @ 2024-07-31 • Rust 包仓库

273 次每月下载
solwalrs 中使用

Apache-2.0

6KB
57

name_variant

生成打印枚举变体名称的方法。

示例

 use name_variant::NamedVariant;

 #[derive(NamedVariant)]
 enum TestEnum {
     A,
     B(),
     C(i32, i32),
     D { _name: String, _age: i32 },
     VariantTest,
 }

 fn main() {
     let x = TestEnum::C(1, 2);
     assert_eq!(x.variant_name(), "C");

     let x = TestEnum::A;
     assert_eq!(x.variant_name(), "A");

     let x = TestEnum::B();
     assert_eq!(x.variant_name(), "B");

     let x = TestEnum::D {_name: "Jane Doe".into(), _age: 30 };
     assert_eq!(x.variant_name(), "D");

     let x = TestEnum::VariantTest;
     assert_eq!(x.variant_name(), "VariantTest");
 }

lib.rs:

生成打印枚举变体名称的方法。

示例

use name_variant::NamedVariant;

#[derive(NamedVariant)]
enum TestEnum {
    A,
    B(),
    C(i32, i32),
    D { _name: String, _age: i32 },
    VariantTest,
}

let x = TestEnum::C(1, 2);
assert_eq!(x.variant_name(), "C");

let x = TestEnum::A;
assert_eq!(x.variant_name(), "A");

let x = TestEnum::B();
assert_eq!(x.variant_name(), "B");

let x = TestEnum::D {_name: "Jane Doe".into(), _age: 30 };
assert_eq!(x.variant_name(), "D");

let x = TestEnum::VariantTest;
assert_eq!(x.variant_name(), "VariantTest");

依赖项

~1.5MB
~36K SLoC