File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,28 @@ But the improvement in output comes at a cost:
193
193
194
194
As you can see, we have to choose one or the other. In either case we have to give something up.
195
195
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
+
196
218
Sometimes, we are * forced* into the first option - sacrificing readability of the source.
197
219
198
220
In some cases, producing excessive whitespace will change meaning of the output.
You can’t perform that action at this time.
0 commit comments