Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Create String from literal string using to_string

  • to_string

  • ToString is a trait that can convert anything to a String.

fn main() {
    let mut text = "abc".to_string();
    println!("{text}");

    text.push_str("efg");
    println!("{text}");
}
abc
abcefg