知识卡片

普通读书笔记卡 · 6074.d.1.a.14 · 生成模型:未记录

输入约束表达类型关系

理解等级:中级

输入的 &impl Summary 接受任意实现 Summary 的类型。两个独立出现的 &impl Summary 各选自己的类型。若要求两者同型,应定义 T: Summary 并让两个引用都写 &T。多项能力使用 +,较长的约束可置于 where。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第10章 泛型类型、trait 与生命周期(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c10.xhtml`,块 0161) - 结论依据:原文对具名 T 和两个输入处 impl Trait 的同型约束给出明确区别。 - 原始内容:The generic type T specified as the type of the item1 and item2 parameters constrains the function such that the concrete type of the value passed as an argument for item1 and item2 must be the same.