pub struct GraftSyntax {
pub cut: String,
pub cut_end: Option<String>,
pub graft: String,
pub full: bool,
pub location: SyntaxLocation,
pub cfg: Option<String>,
pub expressions: Option<GraftExpressions>,
}Expand description
A host-declared external graft cut discovered before code generation. 在代码生成前从宿主入口发现的一条外部 graft 切口。
Fields§
§cut: StringThe cut target: a logical path, or the Rust expression text of a typed
cut. For a range this is the start endpoint, never "start to end".
切口目标:逻辑路径,或类型化切口的 Rust 表达式原文。区间切口这里是起点,
绝不是 "start to end"。
cut_end: Option<String>The far endpoint of a sibling range, as data. 兄弟区间的远端端点,以数据形式携带。
Why the joined-string encoding was wrong: a logical path is free-form
text, so once "a to b" is stored in cut nothing downstream can tell a
range from a single path that literally contains " to " — the four
consumers that re-split cut cut such a path in half. The boundary is
this field: only the parser may decide that a to token was a range
separator, and every consumer reads the endpoints from cut/cut_end.
Pinned by a_path_containing_the_range_word_is_a_single_cut (this file)
and a_string_range_keeps_both_endpoints (build_method).
拼接字符串的编码错在哪:逻辑路径是自由文本,一旦把 "a to b" 存进 cut,
下游就再也分不清区间与一条字面含有 " to " 的路径——四处重新拆分 cut 的
消费方会把这种路径拦腰截断。边界就是本字段:只有解析器能判定某个 to token
是区间分隔符,所有消费方都从 cut/cut_end 读取端点。
由本文件的 a_path_containing_the_range_word_is_a_single_cut 与
build_method 的 a_string_range_keeps_both_endpoints 钉住。
graft: StringThe replacement side, written the same way as cut: a logical selector, a
Rust expression, or an identity.
替换侧,与 cut 使用同一种写法:逻辑选择器、Rust 表达式或身份。
full: boolWhether the replacement covers the whole subtree at the cut target rather than only its node. 替换是否覆盖切口目标的整棵子树,而不只是该节点自身。
location: SyntaxLocationWhere the declaration was written, for diagnostics that point at it. 声明写在哪,供指向它的诊断使用。
cfg: Option<String>The cfg gate the declaration carries, if any, exactly as written.
声明携带的 cfg 门控(若有),按原文保留。
expressions: Option<GraftExpressions>Present when cut(...) / graft(...) supplied Rust expressions. The
renderer emits those expressions verbatim, so the compiler — and any
editor that resolves Rust paths — sees the real target instead of a
string the tooling would have to interpret.
当 cut(...) / graft(...) 给出 Rust 表达式时存在。渲染器会原样发射这些
表达式,因此编译器和任何能解析 Rust 路径的编辑器看到的都是真实目标,
而不是需要工具自己解释的字符串。
Trait Implementations§
Source§impl Clone for GraftSyntax
impl Clone for GraftSyntax
Source§fn clone(&self) -> GraftSyntax
fn clone(&self) -> GraftSyntax
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more