1414
1515use glob:: glob;
1616use regex:: Regex ;
17- use std:: {
18- fmt:: { Write } ,
19- fs,
20- } ;
17+ use std:: { fmt:: Write , fs} ;
2118
2219#[ derive( Debug ) ]
2320struct RustSnippet {
@@ -26,8 +23,8 @@ struct RustSnippet {
2623}
2724
2825fn main ( ) {
29- let mut rust_code = String :: from (
30- r#"// ---------------------------------------------------------------------------
26+ let mut rust_code = String :: from (
27+ r#"// ---------------------------------------------------------------------------
3128// DO NOT EDIT THIS FILE!
3229//
3330// This file is automatically generated by `build.rs`. It collects all Rust
@@ -38,27 +35,33 @@ r#"// --------------------------------------------------------------------------
3835//
3936// To make changes, edit the Rust snippets in the `.mdx` files directly.
4037// ---------------------------------------------------------------------------
41- "# ) ;
38+ "# ,
39+ ) ;
4240 let pattern = "../src/pages/**/*.mdx" ; // Original glob
4341 for entry in glob ( pattern) . unwrap ( ) {
4442 let path = entry. unwrap ( ) ;
4543 println ! ( "cargo:rerun-if-changed={}" , path. display( ) ) ;
4644
4745 let content = fs:: read_to_string ( & path) . expect ( "Failed to read file" ) ;
48-
46+
4947 let snippets = extract_rust_snippets ( & content) ;
5048 if snippets. is_empty ( ) {
5149 continue ;
5250 }
5351
54- let stem = path. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . replace ( '-' , "_" ) ;
52+ let stem = path
53+ . file_stem ( )
54+ . unwrap ( )
55+ . to_str ( )
56+ . unwrap ( )
57+ . replace ( '-' , "_" ) ;
5558
5659 for ( i, snippet) in snippets. iter ( ) . enumerate ( ) {
5760 writeln ! ( rust_code, "#[test]" ) . unwrap ( ) ;
5861 if !snippet. should_run {
5962 writeln ! ( rust_code, "#[ignore]" ) . unwrap ( ) ;
6063 }
61-
64+
6265 writeln ! ( rust_code, "#[allow(dead_code, unused_assignments, unused_variables, unused_imports, unused_mut, non_snake_case)]" ) . unwrap ( ) ;
6366 writeln ! ( rust_code, "fn {stem}_mdx_{i}_test() {{" ) . unwrap ( ) ;
6467 writeln ! ( rust_code, "{}" , snippet. content) . unwrap ( ) ;
@@ -143,4 +146,4 @@ fn extract_rust_snippets(content: &str) -> Vec<RustSnippet> {
143146 }
144147 } )
145148 . collect ( )
146- }
149+ }
0 commit comments