知识卡片

普通读书笔记卡 · 6074.a.1

字符文本与字节需区分

理解等级:中级

u32数值、char、UTF-8文本与任意字节序列有不同有效值约束。char::from_u32返回Option,让调用者处理不合法标量值;unchecked版本则要求调用者证明前提,不能把任意32位数直接当字符。表示转换要明确是在处理数值、字符还是编码字节。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 1. Types Fundamental Types · 查看原书依据

      a u32 value is different from a char, which in turn is different from a sequence of UTF-8 bytes, which in turn is different from a sequence of arbitrary bytes, and it’s up to you to specify exactly which you mean.1 Joel Spolsky’s famous blog post can help you understand which you need. Of course, there are helper methods that allow you to convert between the

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Fundamental Types》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u008-ch01-003)。 - 结论依据:原文在“a u32 value is different from a char”附近的定义、例子或代码支撑本卡核心说明:u32数值、char、UTF-8文本与任意字节序列有不同有效值约束。边界按已读前提解释;示例未执行。 - 原始内容:a u32 value is different from a char, which in turn is different from a sequence of UTF-8 bytes, which in turn is different from a sequence of arbitrary bytes, and it’s up to you to specify exactly which you mean.1 Joel Spolsky’s famous blog post can help you understand which you need. Of course, there are helper methods that allow you to convert between the