2个版本
使用旧的Rust 2015
| 0.1.3 | 2018年8月25日 | 
|---|---|
| 0.1.2 | 2018年7月30日 | 
#1915 in 数据结构
28KB
666 行
lazy_concat
支持迭代和切片的到 String 或 Vec 的延迟连接。
文档
自动生成的文档可以在这里找到。
用法
[dependencies]
lazy_concat = "0.1.1"
extern crate lazy_concat;
use lazy_concat::LazyConcat;
let mut lazy_string = LazyConcat::new(String::new())
    // No allocations happen here
    .and_concat("Hello")
    .and_concat(" ")
    .and_concat("there!");
// Iteration works without any new allocation
for byte in lazy_string.bytes() {
    println!("byte = {:?}", byte);
}
// This extra block scope is not required with #[feature(nll)] (non-linear lifetimes).
{
    // Before taking a slice, make sure the required range is already concatenated
    if lazy_string.slice_needs_normalization(1..4) {
        lazy_string.normalize_to_len(4);
    }
    let slice = lazy_string.get_slice(1..4);
    assert_eq!("ell", slice);
}
// Finally allocate and concatenate the remainder of the string
let string: String = lazy_string.done();
assert_eq!("Hello there!", string);