Skip to content

Chapter 12.4 uses a backslash within a string without explaining what it does #2597

Closed
rust-lang/rust
#87312

Description

@dariuswiles

Listing 12-15 in chapter 12.4 includes the definition of a string:

    let contents = "\
Rust:
safe, fast, productive.
Pick three.";

The use of the backslash on the first line of this definition is not explained, and I don't believe it is covered in the previous chapters. It would be useful to have a short explanation of its purpose.

https://doc.rust-lang.org/reference/tokens.html has this explanation:

... as a special exception, when an unescaped U+005C character (\) occurs immediately before the line-break, then the U+005C character, the line-break, and all whitespace at the beginning of the next line are ignored.

I suggest adding wording similar to the following in the first paragraph after listing 12-15:

The backslash at the end of the first line of contents prevents Rust including a blank line at the beginning of the string.

Activity

  1. added a commit that references this issue on Jul 20, 2021
    b41936b
  2. added a commit that references this issue on Mar 11, 2024
    2a8defb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions