maelstrom-client-process 0.14.0

Client library background process for Maelstrom.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use anyhow::Result;
use maelstrom_base::Sha256Digest;
use maelstrom_util::{async_fs::Fs, io::Sha256Stream};
use std::{path::Path, time::SystemTime};
use tokio::io;

pub async fn calculate_digest(path: &Path) -> Result<(SystemTime, Sha256Digest)> {
    let fs = Fs::new();
    let mut f = fs.open_file(path).await?;
    let mut hasher = Sha256Stream::new(io::sink());
    io::copy(&mut f, &mut hasher).await?;
    let mtime = f.metadata().await?.modified()?;

    Ok((mtime, hasher.finalize().1))
}