知识卡片
表达式中标注泛型参数
函数或方法调用中显式给出泛型参数时,可写 Vec::::with_capacity(1000) 或 iterator.collect::>()。额外的 :: 告诉语法分析器随后的 <…> 是类型参数。若 let ramp: Vec 已提供目标类型,就可把调用简写成 iterator.collect()。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Expressions 调用点自动调整接收者与标注泛型 · 查看原书依据
The problem is that in expressions, < is the less-than operator.
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第05章《Expressions》|调用点自动调整接收者与标注泛型,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch05.xhtml#function-and-method-calls`
- 结论依据:原文用两处比较运算歧义的报错展示 ::<…>,随后用函数签名或变量类型推断展示省略写法。
- 原始内容:The problem is that in expressions, < is the less-than operator.