04 2022 档案

摘要:Rust 语言是静态系统语言,本身不提供反射功能,但是提供了 Any Trait,所有类型(含自定义类型)都自动实现了该特征,所以,我们可以通过它进行一些反射技巧。 获取类型限定名(类型 FullName):std::any::type_name fn main() { println!("{:?} 阅读全文
posted @ 2022-04-27 16:28 Rustln 阅读(1472) 评论(0) 推荐(0) 编辑
摘要:The proc-macro2 crate is a drop-in replacement for proc_macro except that it is available outside of macros - which makes it testable. Its types are a 阅读全文
posted @ 2022-04-26 14:50 Rustln 阅读(1608) 评论(0) 推荐(1) 编辑
摘要:默认值实现 默认值只需要实现 Default trait 即可,如: fn main() { let foo1 = Foo::new(); // 默认值 let foo2 = Foo::default(); } struct Foo { bar: String, baz: i32, foo: boo 阅读全文
posted @ 2022-04-25 11:33 Rustln 阅读(3049) 评论(0) 推荐(1) 编辑
摘要:代码展开(支持宏展开) cargo install cargo-expand 支持 cargo add 添加依赖 cargo install cargo-edit 阅读全文
posted @ 2022-04-21 17:05 Rustln 阅读(180) 评论(0) 推荐(0) 编辑