Lazy concatenation to String
or Vec
, supporting iteration and slices.
Automatic generated documentation can be found here.
Toml
[dependencies]
lazy_concat = "0.1.1"
```Rust extern crate lazyconcat; use lazyconcat::LazyConcat;
let mut lazystring = LazyConcat::new(String::new()) // No allocations happen here .andconcat("Hello") .andconcat(" ") .andconcat("there!");
// Iteration works without any new allocation for byte in lazystring.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 lazystring.sliceneedsnormalization(1..4) { lazystring.normalizetolen(4); } let slice = lazystring.getslice(1..4); asserteq!("ell", slice); } // Finally allocate and concatenate the remainder of the string let string: String = lazystring.done(); asserteq!("Hello there!", string); ```