1 个不稳定版本
使用旧的Rust 2015
| 0.1.4 | 2018年7月13日 |
|---|
#12 in #growable
25KB
376 行
str
lib.rs:
UTF-8编码的可增长字符串。
String2 类型是一种拥有 [char] 所有权控制的字符串类型。
示例
您可以使用 String2::from 从字面量字符串创建一个 String2
use string2::String2;
let hello = String2::from("hello, world!");
您可以使用 char 的 push 方法将其添加到 String2,并使用 push_str 方法添加一个 &str
use string2::String2;
let mut hello = String2::from("Hello, ");
hello.push('w');
hello.push_str("orld!");
如果您有一个 String,您可以使用 from 方法从它创建一个 String2,并可以使用 into 方法将其转换为 String
use string2::String2;
let hello = String::from("Hello world!");
let world = String2::from(hello);
let hello_world: String = world.into();