Crates.io | lazy-transform-str |
lib.rs | lazy-transform-str |
version | 0.0.6 |
source | src |
created_at | 2020-08-26 17:13:54.004918 |
updated_at | 2020-09-22 08:28:56.882679 |
description | Lazy-copying lazy-allocated scanning `str` transformations. This is good e.g. for (un)escaping text, especially if individual strings are short. |
homepage | https://github.com/Tamschi/lazy-transform-str/tree/v0.0.6 |
repository | https://github.com/Tamschi/lazy-transform-str |
max_upload_size | |
id | 281042 |
size | 31,874 |
Lazy-copying lazy-allocated scanning str
transformations.
This is good e.g. for (un)escaping text, especially if individual strings are short.
Please use cargo-edit to always add the latest version of this library:
cargo add lazy-transform-str
use {
cervine::Cow,
gnaw::Unshift as _,
lazy_transform_str::{Transform as _, TransformedPart},
smartstring::alias::String,
};
fn double_a(str: &str) -> Cow<String, str> {
str.transform(|rest /*: &mut &str */| {
// Consume some of the input. `rest` is never empty here.
match rest.unshift().unwrap() {
'a' => TransformedPart::Changed(String::from("aa")),
_ => TransformedPart::Unchanged,
}
} /*: impl FnMut(…) -> … */ )
}
assert_eq!(double_a("abc"), Cow::Owned(String::from("aabc")));
assert_eq!(double_a("bcd"), Cow::Borrowed("bcd"));
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lazy-transform-str
strictly follows Semantic Versioning 2.0.0 with the following exceptions:
This includes the Rust version requirement specified above.
Earlier Rust versions may be compatible, but this can change with minor or patch releases.
Which versions are affected by features and patches can be determined from the respective headings in CHANGELOG.md.