Skip to content

Commit 70faac7

Browse files
Add another "sacrifice readability of source code" example with concat!
Co-authored-by: SabrinaJewson <[email protected]>
1 parent 8012322 commit 70faac7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

text/3830-dedented-string-literals.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,28 @@ But the improvement in output comes at a cost:
193193

194194
As you can see, we have to choose one or the other. In either case we have to give something up.
195195

196+
Another way to format the above would be the following:
197+
198+
```rs
199+
fn main() {
200+
println!(concat!(
201+
"create table student(\n",
202+
" id int primary key,\n",
203+
" name text,\n",
204+
")\n",
205+
));
206+
}
207+
```
208+
209+
The above:
210+
- Is formatted nicely by `rustfmt`
211+
- Produces the correct output
212+
213+
However, it looks very noisy.
214+
- Each line ends with an escaped `\n`.
215+
- Requires double-quotes around each line.
216+
- This does not allow for interpolations, such as `{variable_name}` as the format string is expanded by a macro.
217+
196218
Sometimes, we are *forced* into the first option - sacrificing readability of the source.
197219

198220
In some cases, producing excessive whitespace will change meaning of the output.

0 commit comments

Comments
 (0)