append a string to the end of another string in rust

You can append one string to another using Rust's built-in string concatenation methods. You can take advantage of the push_str method which can append a string slice to the end of another string.

main.rs
fn main() {
    let mut hello = String::from("Hello, ");
    let world = "world!";

    hello.push_str(world);

    println!("{}", hello);
}
141 chars
9 lines

In this example, hello is a mutable String with an initial value of "Hello, ". The world string slice is then appended to hello using the push_str method. Finally, hello is printed to the console which will display "Hello, world!".

gistlibby LogSnag