55
66use rustc_data_structures:: fx:: FxHasher ;
77use std:: hash:: Hasher ;
8- use std:: path:: PathBuf ;
8+ use std:: path:: { Path , PathBuf } ;
99use std:: { fmt, str} ;
1010
1111pub ( crate ) struct StaticFile {
12- pub ( crate ) filename : & ' static str ,
12+ pub ( crate ) filename : PathBuf ,
1313 pub ( crate ) bytes : & ' static [ u8 ] ,
1414}
1515
1616impl StaticFile {
17+ fn new ( filename : & str , bytes : & ' static [ u8 ] ) -> StaticFile {
18+ Self { filename : static_filename ( filename, bytes) , bytes }
19+ }
20+
1721 pub ( crate ) fn minified ( & self ) -> Vec < u8 > {
1822 if self . filename . ends_with ( ".css" ) {
1923 minifier:: css:: minify ( str:: from_utf8 ( self . bytes ) . unwrap ( ) ) . unwrap ( ) . to_string ( ) . into ( )
@@ -24,8 +28,8 @@ impl StaticFile {
2428 }
2529 }
2630
27- pub ( crate ) fn output_filename ( & self ) -> PathBuf {
28- static_filename ( self . filename , self . bytes )
31+ pub ( crate ) fn output_filename ( & self ) -> & Path {
32+ & self . filename
2933 }
3034}
3135
@@ -66,13 +70,18 @@ macro_rules! static_files {
6670 $( pub $field: StaticFile , ) +
6771 }
6872
69- pub ( crate ) const STATIC_FILES : StaticFiles = StaticFiles {
70- $( $field: StaticFile { filename : $file_path, bytes : include_bytes!( $file_path) } , ) +
71- } ;
73+ pub ( crate ) static STATIC_FILES : std :: sync :: LazyLock < StaticFiles > = std :: sync :: LazyLock :: new ( || StaticFiles {
74+ $( $field: StaticFile :: new ( $file_path, include_bytes!( $file_path) ) , ) +
75+ } ) ;
7276
73- pub ( crate ) static STATIC_FILES_LIST : & [ & ' static StaticFile ] = & [
77+ pub ( crate ) fn for_each<E >( f: impl Fn ( & StaticFile ) -> Result <( ) , E >) -> Result <( ) , E > {
78+ for sf in [
7479 $( & STATIC_FILES . $field, ) +
75- ] ;
80+ ] {
81+ f( sf) ?
82+ }
83+ Ok ( ( ) )
84+ }
7685 }
7786}
7887
0 commit comments