@@ -185,7 +185,7 @@ fn sanitize_name(name: &str) -> String {
185185struct Source < ' s > {
186186 shebang : Option < & ' s str > ,
187187 info : Option < & ' s str > ,
188- frontmatter : Option < String > ,
188+ frontmatter : Option < & ' s str > ,
189189 content : & ' s str ,
190190}
191191
@@ -234,14 +234,11 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
234234 0 => {
235235 return Ok ( source) ;
236236 }
237- 1 if tick_char == '#' => {
238- // Attribute
239- return Ok ( source) ;
240- }
241- 2 if tick_char == '#' => {
242- return split_prefix_source ( source, "##" ) ;
243- }
244237 1 | 2 => {
238+ if tick_char == '#' {
239+ // Attribute
240+ return Ok ( source) ;
241+ }
245242 anyhow:: bail!( "found {tick_end} `{tick_char}` in rust frontmatter, expected at least 3" )
246243 }
247244 _ => source. content . split_at ( tick_end) ,
@@ -255,7 +252,7 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
255252 let Some ( ( frontmatter, content) ) = source. content . split_once ( fence_pattern) else {
256253 anyhow:: bail!( "no closing `{fence_pattern}` found for frontmatter" ) ;
257254 } ;
258- source. frontmatter = Some ( frontmatter. to_owned ( ) ) ;
255+ source. frontmatter = Some ( frontmatter) ;
259256 source. content = content;
260257
261258 let ( line, content) = source
@@ -271,22 +268,6 @@ fn split_source(input: &str) -> CargoResult<Source<'_>> {
271268 Ok ( source)
272269}
273270
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-
290271#[ cfg( test) ]
291272mod test_expand {
292273 use super :: * ;
@@ -394,7 +375,7 @@ fn main() {}
394375 }
395376
396377 #[ test]
397- fn test_dash_fence ( ) {
378+ fn test_dash ( ) {
398379 snapbox:: assert_matches (
399380 r#"[[bin]]
400381name = "test-"
@@ -427,7 +408,7 @@ fn main() {}
427408 }
428409
429410 #[ test]
430- fn test_hash_fence ( ) {
411+ fn test_hash ( ) {
431412 snapbox:: assert_matches (
432413 r#"[[bin]]
433414name = "test-"
@@ -455,37 +436,6 @@ strip = true
455436time="0.1.25"
456437###
457438fn 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() {}
489439"# ) ,
490440 ) ;
491441 }
0 commit comments