11 个不稳定版本 (3 个重大变更)
使用旧的 Rust 2015
| 0.4.1 | 2017年3月8日 |
|---|---|
| 0.4.0 | 2017年2月22日 |
| 0.3.6 | 2016年12月7日 |
| 0.3.5 | 2016年10月22日 |
| 0.1.0 | 2016年7月27日 |
#1209 in 数据结构
47KB
946 行
synthax
使用准引用插件合成语法。
在 Apache License 2.0 许可下发布。
有关向此仓库贡献的指南,请参阅 CONTRIBUTING.md。
lib.rs:
使用准引用插件合成语法。
此crate提供的准引用插件的行为类似于 libsyntax 提供的插件(即,#![feature(quote)]),但有两点不同。
首先,表达式的结果可以通过将表达式括在 ${..} 中直接引用,而无需中间变量。例如,要引用切片 tokens 的第一个元素,请编写 ${tokens[0]}。
let tokens = &[Token::Eq, Token::Semi];
let stmt = quote_stmt!(context, let foo ${tokens[0]} bar ${tokens[1]});
其次,包含可引用值的切片和 Vec 可以在序列中进行引用。序列的编写方式与宏中的序列类似,并具有类似的行为。例如,要使用 , 在每个引用值之间引用切片 idents 的值,请编写 $($ident), *。
let idents = &[context.ident_of("foo"), context.ident_of("bar"), context.ident_of("baz")];
let pat = quote_pat!(context, Struct { $(ref $idents), * });
let pat = quote_pat!(context, Struct { $(ref mut ${&idents[..1]}), * });
插件
quote_token_trees!quote_arg!quote_arm!quote_attribute!quote_bare_fn_ty!quote_block!quote_expr!quote_field!quote_field_pat!quote_fn_decl!quote_foreign_item!quote_foreign_mod!quote_generics!quote_impl_item!quote_item!quote_lifetime!quote_lit!quote_local!quote_meta_item!quote_pat!quote_path!quote_stmt!quote_struct_field!quote_trait_item!quote_ty!quote_variant!quote_where_clause!