用于在运行时访问结构字段名称的 proc 宏

时间:2021-06-28 18:31:25
【文件属性】:
文件名称:用于在运行时访问结构字段名称的 proc 宏
文件大小:10KB
文件格式:ZIP
更新时间:2021-06-28 18:31:25
rust proc-macro 字段名称field_names是一个 Rust crate,用于在运行时将源代码中的字段或变量名称公开为字符串。例子考虑一个像这样的简单结构。#[derive(FieldNames)]structExample { hello:String , world:String , #[field_names(skip)] ignore_me:bool , }field_names将发出以下信息:#[automatically_derived]implExample {const FIELDS: [&'staticstr ;2 ]= ["hello" ,"world" , ]; }枚举是相同的:#[derive(VariantNames)]enumExample {Hello (String ), #[variant_names(skip)]Secret (String ), World, }field_names将发出以下信息:#[automatically_derived]implExample {const VARIANTS
【文件预览】:
field_names-master
----.gitignore(19B)
----src()
--------variants.rs(2KB)
--------fields.rs(2KB)
--------lib.rs(832B)
----LICENSE(1KB)
----CHANGELOG.md(128B)
----Cargo.toml(514B)
----.github()
--------workflows()
----examples()
--------variants.rs(284B)
--------generics.rs(188B)
--------hello_world.rs(256B)
----README.md(2KB)
----tests()
--------keep_in_sync.rs(6KB)

网友评论