#string #str #no-std

no-std copy_from_str

An extension trait to copy a string into another string

10 releases (stable)

1.0.6 Sep 17, 2023
1.0.5 Jan 27, 2022
1.0.3 Jan 1, 2021
1.0.2 Jun 6, 2018
0.1.1 Mar 22, 2018

#249 in Rust patterns

Download history 151/week @ 2024-07-22 82/week @ 2024-07-29 70/week @ 2024-08-05 76/week @ 2024-08-12 74/week @ 2024-08-19 83/week @ 2024-08-26 225/week @ 2024-09-02 429/week @ 2024-09-09 741/week @ 2024-09-16 540/week @ 2024-09-23 515/week @ 2024-09-30 479/week @ 2024-10-07 846/week @ 2024-10-14 467/week @ 2024-10-21 446/week @ 2024-10-28 452/week @ 2024-11-04

2,274 downloads per month
Used in errno-no-std

MIT/Apache

7KB

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

lib.rs:

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

No runtime deps