Parcourir la Source

strings

`&str` are "string slices" and (usually?) statically allocated, at least
when specified as literals.  `String`s, on the other hand, are allocated
on the heap and mutable.
Lucas Stadler 10 ans auparavant
Parent
commit
35e6e50371
1 fichiers modifiés avec 8 ajouts et 0 suppressions
  1. 8 0
      rust/book/src/main.rs

+ 8 - 0
rust/book/src/main.rs

@ -92,4 +92,12 @@ fn main() {
92 92
    for x in 0..10 {
93 93
        println!("{}", x);
94 94
    }
95
96
    // strings
97
    let string_slice = "Hello, World!";
98
    let mut string = string_slice.to_string();
99
    println!("{} = {}", string_slice, string);
100
101
    string.push_str(" (again...)");
102
    println!("{}", string);
95 103
}