lazy-transform-str

Crates.iolazy-transform-str
lib.rslazy-transform-str
version0.0.6
sourcesrc
created_at2020-08-26 17:13:54.004918
updated_at2020-09-22 08:28:56.882679
descriptionLazy-copying lazy-allocated scanning `str` transformations. This is good e.g. for (un)escaping text, especially if individual strings are short.
homepagehttps://github.com/Tamschi/lazy-transform-str/tree/v0.0.6
repositoryhttps://github.com/Tamschi/lazy-transform-str
max_upload_size
id281042
size31,874
Tamme Schichler (Tamschi)

documentation

https://docs.rs/lazy-transform-str/0.0.6

README

lazy-transform-str

Lib.rs Crates.io Docs.rs

Rust 1.42.0 Build Status Crates.io - License

GitHub open issues open pull requests crev reviews

Lazy-copying lazy-allocated scanning str transformations.

This is good e.g. for (un)escaping text, especially if individual strings are short.

Installation

Please use cargo-edit to always add the latest version of this library:

cargo add lazy-transform-str

Example

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"));

License

Licensed under either of

at your option.

Contribution

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.

Code of Conduct

Changelog

Versioning

lazy-transform-str strictly follows Semantic Versioning 2.0.0 with the following exceptions:

  • The minor version will not reset to 0 on major version changes (except for v1).
    Consider it the global feature level.
  • The patch version will not reset to 0 on major or minor version changes (except for v0.1 and v1).
    Consider it the global patch level.

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.

Commit count: 42

cargo fmt