在以下示例中,取自nom
,字符串__impl
出现在第一个模式中。这个元素在形式语法方面是什么?它为什么存在?
我的印象是模式中的文字__impl
和后续调用在模式匹配期间用作虚拟字符串,以将内部使用的模式与公共模式分开。但是,“内部”匹配臂也会隐藏rustdoc
。 __impl
- 部分对Rust更重要吗?
#[macro_export]
macro_rules! map(
// Internal parser, do not use directly
(__impl $i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
...
);
($i:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
map!(__impl $i, $submac!($($args)*), $g);
);
($i:expr, $f:expr, $g:expr) => (
map!(__impl $i, call!($f), $g);
);
);
答案 0 :(得分:4)
我的印象是模式中的文字
__impl
和后续调用在模式匹配期间用作虚拟字符串,以将内部使用的模式与公共模式分开。
这是正确的。这是用户不应该知道或使用的内部实现细节。但是,宏必须是公开的,因为它们最终会在使用站点“由用户”扩展。
但是,“内部”匹配臂也会隐藏
rustdoc
。
我不知道你的意思,那只手is in the documentation:
另见:
__impl
- 部分对Rust更重要吗?
没有。很多时候,您会看到此模式与另一个不太可能发生的印记(例如@
或~
)相同。