fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
    match fs2::read_to_string(path) {
        Ok(ref old_contents) if normalize(old_contents) == normalize(contents) => {
            return Ok(());
        }
        _ => (),
    }
    if mode == Mode::Verify {
        anyhow::bail!("`{}` is not up-to-date", path.display());
    }
    eprintln!("updating {}", path.display());
    fs2::write(path, contents)?;
    return Ok(());

    fn normalize(s: &str) -> String {
        s.replace("\r\n", "\n")
    }
}
/// A helper to update file on disk if it has changed.
/// With verify = false,
A helper to update file on disk if it has changed.
With verify = false.
A helper to update file on disk if it has changed . With verify = false .
fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
    match fs2::read_to_string(path) {
        Ok(ref old_contents) if normalize(old_contents) == normalize(contents) => {
            return Ok(());
        }
        _ => (),
    }
    if mode == Mode::Verify {
        anyhow::bail!("`{}` is not up-to-date", path.display());
    }
    eprintln!("updating {}", path.display());
    fs2::write(path, contents)?;
    return Ok(());
    fn normalize(s: &str) -> String {
        s.replace("\r\n", "\n")
    }
}
fn update ( path : & Path , contents : & str , mode : Mode ) -> Result < ( ) > { match fs2 :: read_to_string ( path ) { Ok ( ref old_contents ) if normalize ( old_contents ) == normalize ( contents ) => { return Ok ( ( ) ) ; } _ => ( ) , } if mode == Mode :: Verify { anyhow :: bail ! ( " " path display ( ) ) ; } eprintln ! ( " " path display ( ) ) ; fs2 :: write ( path , contents ) ? ; return Ok ( ( ) ) ; fn normalize ( s : & str ) -> String { s . replace ( " \r \n " , " \n " ) } }
A helper to update file on disk if it has changed.
A helper to update file on disk if it has changed .
path
&Path
contents
&str
mode
Mode
path
&Path
contents
&str
mode
Mode