copy_from_str

Crates.iocopy_from_str
lib.rscopy_from_str
version1.0.6
sourcesrc
created_at2018-03-22 11:45:39.019188
updated_at2023-09-17 14:55:13.32395
descriptionAn extension trait to copy a string into another string
homepage
repositoryhttps://github.com/xfix/copy_from_str
max_upload_size
id56885
size18,312
Kamila Borowska (xfix)

documentation

https://docs.rs/copy_from_str

README

copy_from_str

Extension methods for copying strings into a string.

This crate provides copy_from_str function which can be used to mutate Rust strings. It works similarly to copy_from_slice from standard library except it is for strings.

Examples

use copy_from_str::CopyFromStrExt;

fn make_ascii_uppercase(mut input: &mut str) {
    let mut buffer = [0; 4];
    while let Some(ch) = input.chars().next() {
        let src = ch.to_ascii_uppercase().encode_utf8(&mut buffer);
        let (to_uppercase, rest) = { input }.split_at_mut(ch.len_utf8());
        to_uppercase.copy_from_str(src);
        input = rest;
    }
}

let mut str = String::from("Hello, world! 💯");
make_ascii_uppercase(&mut str);
assert_eq!(str, "HELLO, WORLD! 💯");
Commit count: 38

cargo fmt