about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2015-11-05 15:58:08 +0100
committerSteve Klabnik <steve@steveklabnik.com>2015-11-06 17:58:27 +0100
commit586eb3d50fa964fe3d9bd7f36b6f2a4341774e00 (patch)
tree335724616239c503a3bf70bb979f0930aa85cd9b
parenta216e847272ddbd3033037b606eaf2d801c250b9 (diff)
downloadrust-586eb3d50fa964fe3d9bd7f36b6f2a4341774e00.tar.gz
rust-586eb3d50fa964fe3d9bd7f36b6f2a4341774e00.zip
Add multi-line string literals to TRPL
Fixes #29591
-rw-r--r--src/doc/trpl/strings.md26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/doc/trpl/strings.md b/src/doc/trpl/strings.md
index 18483664989..f61b4d8ed8d 100644
--- a/src/doc/trpl/strings.md
+++ b/src/doc/trpl/strings.md
@@ -24,9 +24,29 @@ compiled program, and exists for the entire duration it runs. The `greeting`
 binding is a reference to this statically allocated string. String slices
 have a fixed size, and cannot be mutated.
 
-A `String`, on the other hand, is a heap-allocated string. This string is
-growable, and is also guaranteed to be UTF-8. `String`s are commonly created by
-converting from a string slice using the `to_string` method.
+String literals can span multiple lines. There are two forms. The first will
+include the newline and the leading spaces:
+
+```rust
+let s = "foo
+    bar";
+
+assert_eq!("foo\n        bar", s);
+```
+
+The second, with a `\`, does not trim the spaces:
+
+```rust
+let s = "foo\
+    bar"; 
+
+assert_eq!("foobar", s);
+```
+
+Rust has more than just `&str`s though. A `String`, is a heap-allocated string.
+This string is growable, and is also guaranteed to be UTF-8. `String`s are
+commonly created by converting from a string slice using the `to_string`
+method.
 
 ```rust
 let mut s = "Hello".to_string(); // mut s: String