Skip to content

Commit d333838

Browse files
Nemo157jyn514
authored andcommitted
Simplify file writing
1 parent af56f94 commit d333838

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

build.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::{Context as _, Error, Result};
22
use git2::Repository;
3-
use std::{env, fs::File, io::Write, path::Path};
3+
use std::{env, path::Path};
44

55
fn main() -> Result<()> {
66
let out_dir = env::var("OUT_DIR").context("missing OUT_DIR")?;
@@ -16,10 +16,11 @@ fn write_git_version(out_dir: &Path) -> Result<()> {
1616
let git_hash = maybe_hash.as_deref().unwrap_or("???????");
1717

1818
let build_date = time::OffsetDateTime::now_utc().date();
19-
let dest_path = out_dir.join("git_version");
2019

21-
let mut file = File::create(&dest_path)?;
22-
write!(file, "({} {})", git_hash, build_date)?;
20+
std::fs::write(
21+
out_dir.join("git_version"),
22+
format!("({} {})", git_hash, build_date),
23+
)?;
2324

2425
// TODO: are these right?
2526
println!("cargo:rerun-if-changed=.git/HEAD");
@@ -78,8 +79,7 @@ fn compile_sass_file(
7879

7980
let css = context.compile().map_err(Error::msg)?;
8081
let dest_path = out_dir.join(format!("{}.css", target));
81-
let mut file = File::create(&dest_path)?;
82-
file.write_all(css.as_bytes())?;
82+
std::fs::write(dest_path, css)?;
8383

8484
Ok(())
8585
}

0 commit comments

Comments
 (0)