tinted-builder-rust 0.19.0

Simple Base16, Base24 and Tinted8 compliant rendering of mustache templates
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use anyhow::{Context, Result};
use std::fs::{remove_file, File};
use std::io::Write;
use std::path::Path;

pub fn write_to_file(path: impl AsRef<Path>, contents: &str) -> Result<()> {
    if path.as_ref().exists() {
        remove_file(path.as_ref())
            .with_context(|| format!("Unable to remove file: {}", path.as_ref().display()))?;
    }

    let mut file = File::create(path.as_ref())
        .with_context(|| format!("Unable to create file: {}", path.as_ref().display()))?;

    file.write_all(contents.as_bytes())?;

    Ok(())
}