为什么Rust有String和str?String和之间有什么区别str?什么时候使用String而不是str反之亦然?其中一个被弃用了吗?
这是该str类型的使用方式:
let hello = "Hello, world!";
// with an explicit type annotation
let hello: &'static str = "Hello, world!";
Run Code Online (Sandbox Code Playgroud)
let hello: str = "Hello, world!"; 造成 expected `str`, found `&str`
为什么文本的默认类型str与所有原始类型、向量和String? 为什么是参考?
通常,特定值只有一个所有者(除了 之类的Rc<T>)。4那么,由于变量myVar是从某个东西借来的,那么下面这个值的所有者是谁呢?我想知道那是什么东西。
let myVar = &4;
Run Code Online (Sandbox Code Playgroud)