知识卡片
字符串包装有效UTF8
String 是有所有权、可增长的 UTF-8 文本,底层包装字节向量,并维护编码有效性。&str 借用一段已有的 UTF-8 数据,例如字面量指向保存在程序中的文本。需要自己持有文本时可从切片构造 String;只读取时可以接收 &str。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 常用集合 Storing UTF-8 Encoded Text with Strings · 查看原书依据
The String type, which is provided by Rust’s standard library rather than coded into the core language, is a growable, mutable, owned, UTF-8 encoded string type. When Rustaceans refer to “strings” in Rust, they might be referring to either the String or the string slice &str types, not just one of those types.
参考来源
- 位置:《The Rust Programming Language(第2版)》第08章 常用集合(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c08.xhtml`,块 0072)
- 结论依据:原文定义两种字符串形式及其共有的 UTF-8 保证。
- 原始内容:The String type, which is provided by Rust’s standard library rather than coded into the core language, is a growable, mutable, owned, UTF-8 encoded string type. When Rustaceans refer to “strings” in Rust, they might be referring to either the String or the string slice &str types, not just one of those types.