← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 10873 · 生成模型:未记录

接口约束字符串解析

理解等级:中级

trait 描述类型可承诺提供的操作。FromStr 让整数等类型提供关联函数 from_str,调用 u64::from_str 时目标类型决定解析规则。用该 trait 提供的方法时通常要先引入 trait。命令行文本到数值有明确的转换边界。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第01章《A Tour of Rust》|把外部字符串变成已验证的计算输入,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch01.xhtml#handling-command-line-arguments` - 结论依据:原文说明 FromStr 与 u64 的实现关系及作用域要求。 - 原始内容:The first use declaration brings the standard library trait FromStr into scope. A trait is a collection of methods that types can implement.