← 返回刚才阅读的位置

知识卡片

延伸参考卡 · 6074.d.1.a.3.c.11.a.3.e · 生成模型:GPT-6

筛选复制到生成项的属性

理解等级:中级

生成新的 Rust 项时,可以为其选择合用的原属性。书中 Yew 的历史代码遍历输入 attrs,仅复制 allow、deny 和 cfg 到相应的辅助项。这样生成项能保留所需的检查设置与启用条件。对同一属性路径执行查找也可用于验证调用规则,例如 Tokio 测试宏拒绝重复 test 并定位额外的标注。

相关卡片 [[派生辅助属性配置展开]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Write Powerful Rust Macros》第08章《Builder with attributes》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-8.xhtml#p208) - 结论依据:8.9 展示 Yew 通过 should_preserve_attr 选择复制的 allow、deny 和 cfg,旁边的 Tokio 例子使用相同路径匹配定位重复标注。 - 原始内容:Meanwhile, Yew has logic that decides whether the attributes of the original struct should be used in its builder struct. Like Tokio, it uses the is_ident method to compare with strings: