@@ -233,7 +233,8 @@ This allows us to have a more readable version of the above:
233
233
234
234
``` rust
235
235
fn main () {
236
- println! (d "
236
+ println! (
237
+ d "
237
238
create table student(
238
239
id int primary key,
239
240
name text
@@ -258,15 +259,17 @@ Now, consider the example with multiple nested scopes again:
258
259
``` rs
259
260
fn main () {
260
261
{
261
- println! (d "
262
+ println! (
263
+ d "
262
264
create table student(
263
265
id int primary key,
264
266
name text
265
267
)
266
268
"
267
269
);
268
270
}
269
- println! (d "
271
+ println! (
272
+ d "
270
273
create table student(
271
274
id int primary key,
272
275
name text
@@ -275,7 +278,8 @@ fn main() {
275
278
);
276
279
{
277
280
{
278
- println! (d "
281
+ println! (
282
+ d "
279
283
create table student(
280
284
id int primary key,
281
285
name text
@@ -303,7 +307,8 @@ This allows all lines to have a common indentation.
303
307
304
308
``` rust
305
309
fn main () {
306
- println! (d "
310
+ println! (
311
+ d "
307
312
create table student(
308
313
id int primary key,
309
314
name text
@@ -333,13 +338,14 @@ In order to strip the first level of indentation, the ending quote is aligned to
333
338
334
339
``` rust
335
340
fn main () {
336
- println! (d "
337
- create table student(
338
- id int primary key,
339
- name text
340
- )
341
- "
342
- ^^^^ // common leading whitespace (will be removed)
341
+ println! (
342
+ d "
343
+ create table student(
344
+ id int primary key,
345
+ name text
346
+ )
347
+ "
348
+ ^^^^^^^^ // common leading whitespace (will be removed)
343
349
);
344
350
}
345
351
```
@@ -363,7 +369,8 @@ All indentation can be stripped by placing the closing double quote on the same
363
369
364
370
``` rust
365
371
fn main () {
366
- println! (d "
372
+ println! (
373
+ d "
367
374
create table student(
368
375
id int primary key,
369
376
name text
@@ -403,7 +410,8 @@ create table student(
403
410
404
411
``` rs
405
412
fn main () {
406
- println! (d "
413
+ println! (
414
+ d "
407
415
create table student(
408
416
id int primary key,
409
417
name text
@@ -419,7 +427,8 @@ fn main() {
419
427
420
428
``` rs
421
429
fn main () {
422
- println! (d "
430
+ println! (
431
+ d "
423
432
create table student(
424
433
id int primary key,
425
434
name text
@@ -434,7 +443,8 @@ fn main() {
434
443
435
444
``` rs
436
445
fn main () {
437
- println! (d "
446
+ println! (
447
+ d "
438
448
create table student(
439
449
id int primary key,
440
450
name text
@@ -470,7 +480,8 @@ The `format_args!` macro, and by extension all wrapper macros that pass argument
470
480
fn main () {
471
481
let table_name = " student" ;
472
482
473
- println! (d "
483
+ println! (
484
+ d "
474
485
create table {table_name}(
475
486
id int primary key,
476
487
name text
@@ -566,7 +577,8 @@ You can use them in formatting macros, such as `println!`, `write!`, `assert_eq!
566
577
``` rs
567
578
let message = " Hello, world!" ;
568
579
569
- let py = format! (dr #"
580
+ let py = format! (
581
+ dr #"
570
582
def hello():
571
583
print(" {message }" )
572
584
@@ -589,7 +601,9 @@ let mut py = String::new();
589
601
590
602
// Note: Using `writeln!` because the final newline from dedented strings is removed. (more info later)
591
603
592
- writeln! (py , d "
604
+ writeln! (
605
+ py ,
606
+ d "
593
607
def hello():
594
608
"
595
609
// ^^ removed
@@ -601,14 +615,18 @@ writeln!(py, d"
601
615
// to insert the 2nd newline
602
616
603
617
// Remember, dedented string literals strip the last newline.
604
- writeln! (py , dr #"
618
+ writeln! (
619
+ py ,
620
+ dr #"
605
621
print(" {message }" )
606
622
607
623
" #
608
624
// ^^ kept
609
625
);
610
626
611
- write! (py , d "
627
+ write! (
628
+ py ,
629
+ d "
612
630
hello()
613
631
"
614
632
);
@@ -959,7 +977,8 @@ Consider the following which is invalid:
959
977
``` rs
960
978
fn main () {
961
979
// ERROR
962
- println! (d " create table student(
980
+ println! (
981
+ d " create table student(
963
982
id int primary key,
964
983
name text
965
984
)
@@ -975,7 +994,8 @@ The following is also incorrect, as there is no newline before the line containi
975
994
976
995
``` rs
977
996
fn main () {
978
- println! (d "
997
+ println! (
998
+ d "
979
999
create table student(
980
1000
id int primary key,
981
1001
name text
@@ -995,7 +1015,8 @@ string content is allowed:
995
1015
996
1016
``` rs
997
1017
fn main () {
998
- println! (d "
1018
+ println! (
1019
+ d "
999
1020
create table student(
1000
1021
id int primary key,
1001
1022
name text
@@ -1009,7 +1030,8 @@ Reason: turning this into a syntax error is too strict, when it can be auto-fixe
1009
1030
1010
1031
``` rs
1011
1032
fn main () {
1012
- println! (d "
1033
+ println! (
1034
+ d "
1013
1035
create table student(
1014
1036
id int primary key,
1015
1037
name text
@@ -1068,7 +1090,8 @@ Differences:
1068
1090
However, in this RFC the following:
1069
1091
1070
1092
```rs
1071
- print!(d"
1093
+ print!(
1094
+ d"
1072
1095
a
1073
1096
"
1074
1097
^^^^ // common leading whitespace (will be removed)
@@ -1082,7 +1105,8 @@ Differences:
1082
1105
In order to add a newline at the end, you have to add a newline in the source code:
1083
1106
1084
1107
```rs
1085
- print!(d"
1108
+ print!(
1109
+ d"
1086
1110
a
1087
1111
1088
1112
"
@@ -1287,7 +1311,8 @@ One of the major benefits of having dedented string literals is that you'll be a
1287
1311
let message = " Hello, world!" ;
1288
1312
1289
1313
// `{message}` is interpolated
1290
- let py = format! (dr #"
1314
+ let py = format! (
1315
+ dr #"
1291
1316
def hello():
1292
1317
print(" {message }" )
1293
1318
@@ -1512,11 +1537,11 @@ With [postfix macros](https://github.com/rust-lang/rfcs/pull/2442), the situatio
1512
1537
fn main () {
1513
1538
println! (
1514
1539
"
1515
- create table student(
1516
- id int primary key,
1517
- name text
1518
- )
1519
- " . dedent! ()
1540
+ create table student(
1541
+ id int primary key,
1542
+ name text
1543
+ )
1544
+ " . dedent! ()
1520
1545
);
1521
1546
}
1522
1547
```
@@ -1605,13 +1630,15 @@ If indentation of the dedented string does not match the surrounding code:
1605
1630
1606
1631
``` rust
1607
1632
fn main () {
1608
- println! (d "
1609
- create table student(
1610
- id int primary key,
1611
- name text
1612
- )
1613
- " );
1614
- ^^^^ // common leading whitespace (will be removed)
1633
+ println! (
1634
+ d "
1635
+ create table student(
1636
+ id int primary key,
1637
+ name text
1638
+ )
1639
+ "
1640
+ ^^^^^^^^ // common leading whitespace (will be removed)
1641
+ );
1615
1642
}
1616
1643
```
1617
1644
0 commit comments