File tree 1 file changed +23
-3
lines changed
1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -24,9 +24,29 @@ compiled program, and exists for the entire duration it runs. The `greeting`
24
24
binding is a reference to this statically allocated string. String slices
25
25
have a fixed size, and cannot be mutated.
26
26
27
- A ` String ` , on the other hand, is a heap-allocated string. This string is
28
- growable, and is also guaranteed to be UTF-8. ` String ` s are commonly created by
29
- converting from a string slice using the ` to_string ` method.
27
+ String literals can span multiple lines. There are two forms. The first will
28
+ include the newline and the leading spaces:
29
+
30
+ ``` rust
31
+ let s = " foo
32
+ bar" ;
33
+
34
+ assert_eq! (" foo\ n bar" , s );
35
+ ```
36
+
37
+ The second, with a ` \ ` , does not trim the spaces:
38
+
39
+ ``` rust
40
+ let s = " foo\
41
+ bar" ;
42
+
43
+ assert_eq! (" foobar" , s );
44
+ ```
45
+
46
+ Rust has more than just ` &str ` s though. A ` String ` , is a heap-allocated string.
47
+ This string is growable, and is also guaranteed to be UTF-8. ` String ` s are
48
+ commonly created by converting from a string slice using the ` to_string `
49
+ method.
30
50
31
51
``` rust
32
52
let mut s = " Hello" . to_string (); // mut s: String
You can’t perform that action at this time.
0 commit comments