1
- #![ allow( clippy:: style) ]
2
1
3
2
use std:: env;
4
- use std:: path:: PathBuf ;
3
+ use std:: path:: { Path , PathBuf } ;
4
+
5
5
6
6
fn main ( ) {
7
7
let ac = autocfg:: new ( ) ;
@@ -15,11 +15,12 @@ fn main() {
15
15
16
16
let outdir: PathBuf = std:: env:: var_os ( "OUT_DIR" ) . unwrap ( ) . into ( ) ;
17
17
write_default_precision_file ( & outdir) ;
18
+ write_default_rounding_mode ( & outdir) ;
18
19
}
19
20
20
21
21
22
/// Create default_precision.rs, containg definition of constant DEFAULT_PRECISION loaded in src/lib.rs
22
- fn write_default_precision_file ( outdir : & PathBuf ) {
23
+ fn write_default_precision_file ( outdir : & Path ) {
23
24
let env_var = env:: var ( "RUST_BIGDECIMAL_DEFAULT_PRECISION" ) . unwrap_or_else ( |_| "100" . to_owned ( ) ) ;
24
25
println ! ( "cargo:rerun-if-env-changed=RUST_BIGDECIMAL_DEFAULT_PRECISION" ) ;
25
26
@@ -34,3 +35,14 @@ fn write_default_precision_file(outdir: &PathBuf) {
34
35
35
36
std:: fs:: write ( rust_file_path, rust_file_contents) . unwrap ( ) ;
36
37
}
38
+
39
+ /// Create default_rounding_mode.rs, using value of RUST_BIGDECIMAL_DEFAULT_ROUNDING_MODE environment variable
40
+ fn write_default_rounding_mode ( outdir : & Path ) {
41
+ let rounding_mode_name = env:: var ( "RUST_BIGDECIMAL_DEFAULT_ROUNDING_MODE" ) . unwrap_or_else ( |_| "HalfEven" . to_owned ( ) ) ;
42
+ println ! ( "cargo:rerun-if-env-changed=RUST_BIGDECIMAL_DEFAULT_ROUNDING_MODE" ) ;
43
+
44
+ let rust_file_path = outdir. join ( "default_rounding_mode.rs" ) ;
45
+ let rust_file_contents = format ! ( "const DEFAULT_ROUNDING_MODE: RoundingMode = RoundingMode::{};" , rounding_mode_name) ;
46
+
47
+ std:: fs:: write ( rust_file_path, rust_file_contents) . unwrap ( ) ;
48
+ }
0 commit comments