Skip to content
Discussion options

You must be logged in to vote

Embedding formatted text in Rust's string literals forces us to make a choice:

  • Sacrifice readability of the output
  • Sacrifice readability of the source code

Sacrifice readability of the output

In order to print the following:

create table student(
    id int primary key,
    name text
)

The initial attempt might look as follows:

fn main() {
    println!("
        create table student(
            id int primary key,
            name text
        )
    ");
}

Which outputs (using ^ to mark the beginning of a line, and · to mark a leading space):

^
^········create table student(
^············id int primary key,
^············name text
^········)
^····
^

The output is formatted in an unconven…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Tahaa-Dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1 on March 21, 2026 09:51.