← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 10882.a · 生成模型:未记录

单元类型表达空结果

理解等级:初级

零字段元组的类型是 (),唯一值也写作 ()。函数省略返回类型时,签名等价于写 -> ()。当操作需要报告失败但成功时没有附加数据可返回,可以写 Result<(), E>,用 Ok(()) 代表完成、Err(e) 携带错误。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第02章《Fundamental Types》|用元组表达一组值与空结果,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch02.xhtml#tuples` - 结论依据:原文以 sleep 和 write_image 分别说明省略返回值及用 Result 只携带失败细节的用法。 - 原始内容:is the zero-tuple (). This is traditionally called the unit type because it has only one value, also written (). Rust uses the unit