5个版本
使用旧的Rust 2015
| 0.1.4 | 2017年8月10日 |
|---|---|
| 0.1.3 | 2017年8月9日 |
| 0.1.2 | 2017年8月4日 |
| 0.1.1 | 2017年8月4日 |
| 0.1.0 | 2017年8月3日 |
在#growable中排名10
24KB
376 行
str
lib.rs:
UTF-8编码的可增长字符串。
Str类型是具有[char]所有权的字符串类型。
示例
您可以使用Str::from从字面量字符串创建一个Str
use str::Str;
let hello = Str::from("hello, world!");
您可以使用push方法将char追加到Str中,并使用push_str方法追加一个&str
use str::Str;
let mut hello = Str::from("Hello, ");
hello.push('w');
hello.push_str("orld!");
如果您有一个String,您可以使用from方法从它创建一个Str,并可以使用into方法将其转换为String
use str::Str;
let hello = String::from("Hello world!");
let world = Str::from(hello);
let hello_world: String = world.into();