@@ -185,7 +185,7 @@ fn sanitize_name(name: &str) -> String {
185
185
struct Source < ' s > {
186
186
shebang : Option < & ' s str > ,
187
187
info : Option < & ' s str > ,
188
- frontmatter : Option < String > ,
188
+ frontmatter : Option < & ' s str > ,
189
189
content : & ' s str ,
190
190
}
191
191
@@ -234,14 +234,11 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
234
234
0 => {
235
235
return Ok ( source) ;
236
236
}
237
- 1 if tick_char == '#' => {
238
- // Attribute
239
- return Ok ( source) ;
240
- }
241
- 2 if tick_char == '#' => {
242
- return split_prefix_source ( source, "##" ) ;
243
- }
244
237
1 | 2 => {
238
+ if tick_char == '#' {
239
+ // Attribute
240
+ return Ok ( source) ;
241
+ }
245
242
anyhow:: bail!( "found {tick_end} `{tick_char}` in rust frontmatter, expected at least 3" )
246
243
}
247
244
_ => source. content . split_at ( tick_end) ,
@@ -255,7 +252,7 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
255
252
let Some ( ( frontmatter, content) ) = source. content . split_once ( fence_pattern) else {
256
253
anyhow:: bail!( "no closing `{fence_pattern}` found for frontmatter" ) ;
257
254
} ;
258
- source. frontmatter = Some ( frontmatter. to_owned ( ) ) ;
255
+ source. frontmatter = Some ( frontmatter) ;
259
256
source. content = content;
260
257
261
258
let ( line, content) = source
@@ -271,22 +268,6 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
271
268
Ok ( source)
272
269
}
273
270
274
- fn split_prefix_source < ' s > ( mut source : Source < ' s > , prefix : & str ) -> CargoResult < Source < ' s > > {
275
- let mut frontmatter = String :: new ( ) ;
276
- while let Some ( rest) = source. content . strip_prefix ( prefix) {
277
- if !rest. is_empty ( ) && !rest. starts_with ( ' ' ) {
278
- anyhow:: bail!( "frontmatter must have a space between `##` and the content" ) ;
279
- }
280
- let ( line, rest) = rest. split_once ( '\n' ) . unwrap_or ( ( rest, "" ) ) ;
281
- frontmatter. push_str ( " " ) ;
282
- frontmatter. push_str ( line) ;
283
- frontmatter. push ( '\n' ) ;
284
- source. content = rest;
285
- }
286
- source. frontmatter = Some ( frontmatter) ;
287
- Ok ( source)
288
- }
289
-
290
271
#[ cfg( test) ]
291
272
mod test_expand {
292
273
use super :: * ;
@@ -394,7 +375,7 @@ fn main() {}
394
375
}
395
376
396
377
#[ test]
397
- fn test_dash_fence ( ) {
378
+ fn test_dash ( ) {
398
379
snapbox:: assert_matches (
399
380
r#"[[bin]]
400
381
name = "test-"
@@ -427,7 +408,7 @@ fn main() {}
427
408
}
428
409
429
410
#[ test]
430
- fn test_hash_fence ( ) {
411
+ fn test_hash ( ) {
431
412
snapbox:: assert_matches (
432
413
r#"[[bin]]
433
414
name = "test-"
@@ -455,37 +436,6 @@ strip = true
455
436
time="0.1.25"
456
437
###
457
438
fn main() {}
458
- "# ) ,
459
- ) ;
460
- }
461
-
462
- #[ test]
463
- fn test_hash_prefix ( ) {
464
- snapbox:: assert_matches (
465
- r#"[[bin]]
466
- name = "test-"
467
- path = [..]
468
-
469
- [dependencies]
470
- time = "0.1.25"
471
-
472
- [package]
473
- autobenches = false
474
- autobins = false
475
- autoexamples = false
476
- autotests = false
477
- build = false
478
- edition = "2021"
479
- name = "test-"
480
-
481
- [profile.release]
482
- strip = true
483
-
484
- [workspace]
485
- "# ,
486
- si ! ( r#"## [dependencies]
487
- ## time="0.1.25"
488
- fn main() {}
489
439
"# ) ,
490
440
) ;
491
441
}
0 commit comments