2020-10-07 22:03:26 +00:00
|
|
|
#![warn(clippy::single_char_add_str)]
|
2023-06-15 19:15:10 +00:00
|
|
|
#![allow(clippy::needless_raw_strings, clippy::needless_raw_string_hashes)]
|
2020-09-13 11:00:45 +00:00
|
|
|
|
2020-09-14 13:31:04 +00:00
|
|
|
macro_rules! get_string {
|
|
|
|
() => {
|
|
|
|
String::from("Hello world!")
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-09-13 11:00:45 +00:00
|
|
|
fn main() {
|
2020-10-07 22:03:26 +00:00
|
|
|
// `push_str` tests
|
|
|
|
|
|
|
|
let mut string = String::new();
|
|
|
|
string.push_str("R");
|
|
|
|
string.push_str("'");
|
|
|
|
|
|
|
|
string.push('u');
|
|
|
|
string.push_str("st");
|
|
|
|
string.push_str("");
|
|
|
|
string.push_str("\x52");
|
|
|
|
string.push_str("\u{0052}");
|
|
|
|
string.push_str(r##"a"##);
|
|
|
|
|
2024-06-09 18:01:00 +00:00
|
|
|
let c_ref = &'a';
|
|
|
|
string.push_str(&c_ref.to_string());
|
|
|
|
let c = 'a';
|
|
|
|
string.push_str(&c.to_string());
|
|
|
|
string.push_str(&'a'.to_string());
|
|
|
|
|
2020-10-07 22:03:26 +00:00
|
|
|
get_string!().push_str("ö");
|
|
|
|
|
|
|
|
// `insert_str` tests
|
|
|
|
|
2020-09-13 11:00:45 +00:00
|
|
|
let mut string = String::new();
|
|
|
|
string.insert_str(0, "R");
|
|
|
|
string.insert_str(1, "'");
|
|
|
|
|
|
|
|
string.insert(0, 'u');
|
|
|
|
string.insert_str(2, "st");
|
|
|
|
string.insert_str(0, "");
|
|
|
|
string.insert_str(0, "\x52");
|
|
|
|
string.insert_str(0, "\u{0052}");
|
|
|
|
let x: usize = 2;
|
|
|
|
string.insert_str(x, r##"a"##);
|
|
|
|
const Y: usize = 1;
|
|
|
|
string.insert_str(Y, r##"a"##);
|
2020-10-30 22:47:22 +00:00
|
|
|
string.insert_str(Y, r##"""##);
|
|
|
|
string.insert_str(Y, r##"'"##);
|
2020-09-14 13:31:04 +00:00
|
|
|
|
2024-06-09 18:01:00 +00:00
|
|
|
string.insert_str(0, &c_ref.to_string());
|
|
|
|
string.insert_str(0, &c.to_string());
|
|
|
|
string.insert_str(0, &'a'.to_string());
|
|
|
|
|
2020-09-14 13:31:04 +00:00
|
|
|
get_string!().insert_str(1, "?");
|
2020-09-13 11:00:45 +00:00
|
|
|
}
|