Skip to content

Commit 8b9bcc3

Browse files
committed
Add section explaining how to have a trailing newline
1 parent 545c941 commit 8b9bcc3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

text/3830-dedented-string-literals.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,33 @@ let py = d"
707707
// OK
708708
```
709709

710+
Both outputs will not contain a newline at the end, since the literal newline is stripped.
711+
712+
If you'd like to have a trailing newline, you can insert a literal newline at the end:
713+
714+
```rust
715+
let py = d"
716+
def hello():
717+
print('Hello, world!')
718+
719+
hello()
720+
721+
";
722+
// OK
723+
```
724+
725+
You can also use an escaped newline. This is fine, because the string still ends with a literal newline (which cannot be escaped):
726+
727+
```rust
728+
let py = d"
729+
def hello():
730+
print('Hello, world!')
731+
732+
hello()\n
733+
";
734+
// OK
735+
```
736+
710737
Benefits the above rules bring include:
711738

712739
- The above rules make all dedented string literals you'll find in Rust consistent.

0 commit comments

Comments
 (0)