5
5
6
6
use rustc_data_structures:: fx:: FxHasher ;
7
7
use std:: hash:: Hasher ;
8
- use std:: path:: PathBuf ;
8
+ use std:: path:: { Path , PathBuf } ;
9
9
use std:: { fmt, str} ;
10
10
11
11
pub ( crate ) struct StaticFile {
12
- pub ( crate ) filename : & ' static str ,
12
+ pub ( crate ) filename : PathBuf ,
13
13
pub ( crate ) bytes : & ' static [ u8 ] ,
14
14
}
15
15
16
16
impl StaticFile {
17
+ fn new ( filename : & str , bytes : & ' static [ u8 ] ) -> StaticFile {
18
+ Self { filename : static_filename ( filename, bytes) , bytes }
19
+ }
20
+
17
21
pub ( crate ) fn minified ( & self ) -> Vec < u8 > {
18
22
if self . filename . ends_with ( ".css" ) {
19
23
minifier:: css:: minify ( str:: from_utf8 ( self . bytes ) . unwrap ( ) ) . unwrap ( ) . to_string ( ) . into ( )
@@ -24,8 +28,8 @@ impl StaticFile {
24
28
}
25
29
}
26
30
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
29
33
}
30
34
}
31
35
@@ -66,13 +70,18 @@ macro_rules! static_files {
66
70
$( pub $field: StaticFile , ) +
67
71
}
68
72
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
+ } ) ;
72
76
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 [
74
79
$( & STATIC_FILES . $field, ) +
75
- ] ;
80
+ ] {
81
+ f( sf) ?
82
+ }
83
+ Ok ( ( ) )
84
+ }
76
85
}
77
86
}
78
87
0 commit comments