@@ -4,40 +4,30 @@ use std::{env, fs};
4
4
use toml:: Value ;
5
5
6
6
fn main ( ) {
7
- let toml_content =
8
- fs:: read_to_string ( "../versions.toml" ) . expect ( "Failed to read versions.toml" ) ;
7
+ let toml_file = "../versions.toml" ;
8
+ let toml_content = fs:: read_to_string ( toml_file ) . expect ( "Failed to read versions.toml" ) ;
9
9
10
10
let config: Value = toml:: from_str ( & toml_content) . expect ( "Failed to parse TOML" ) ;
11
11
12
12
let mut rust_code = String :: from ( "// Auto-generated code from versions.toml\n \n " ) ;
13
13
14
- match config {
15
- Value :: Table ( table) => {
16
- for ( key, val) in table {
17
- match val {
18
- Value :: String ( s) => {
19
- let const_value = format ! ( "\" {}\" " , s) ;
20
- rust_code. push_str ( & format ! (
21
- "pub const {}: &str = {};\n " ,
22
- key. to_uppercase( ) ,
23
- const_value
24
- ) ) ;
25
- }
26
- _ => {
27
- panic ! ( "Invalid value type in versions.toml: {:?}" , val) ;
28
- }
29
- } ;
30
- }
31
- }
32
- _ => {
33
- panic ! ( "Invalid value type in versions.toml: {:?}" , config) ;
34
- }
14
+ let Value :: Table ( table) = config else {
15
+ panic ! ( "Invalid value type in versions.toml: {config:?}" ) ;
16
+ } ;
17
+ for ( key, val) in table {
18
+ let Value :: String ( s) = val else {
19
+ panic ! ( "Invalid value type in versions.toml: {val:?}" ) ;
20
+ } ;
21
+ rust_code. push_str ( & format ! (
22
+ "pub const {}: &str = {s:?};\n " ,
23
+ key. to_uppercase( )
24
+ ) ) ;
35
25
}
36
26
37
27
let out_dir = env:: var_os ( "OUT_DIR" ) . unwrap ( ) ;
38
28
let dest_path = Path :: new ( & out_dir) . join ( "versions.rs" ) ;
39
29
fs:: write ( & dest_path, rust_code) . expect ( "Failed to write generated code" ) ;
40
30
41
31
// Tell Cargo to rerun this script if the TOML file changes
42
- println ! ( "cargo:rerun-if-changed=../versions.toml " ) ;
32
+ println ! ( "cargo:rerun-if-changed={toml_file} " ) ;
43
33
}
0 commit comments