diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-04-23 08:07:10 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-04-23 08:07:10 +0300 |
commit | 486f5f69b6e2d10eafa44c28b93caa8454e48911 (patch) | |
tree | 483dbe07960555d48b4dc7392be94077abf70f0a | |
parent | c494f88db3d86a13134a6e86ee7e0246ab9d3943 (diff) | |
download | summain-rs-486f5f69b6e2d10eafa44c28b93caa8454e48911.tar.gz |
first steps for async
-rw-r--r-- | src/bin/summain.rs | 9 | ||||
-rw-r--r-- | src/lib.rs | 2 |
2 files changed, 7 insertions, 4 deletions
diff --git a/src/bin/summain.rs b/src/bin/summain.rs index 76982b9..8526759 100644 --- a/src/bin/summain.rs +++ b/src/bin/summain.rs @@ -1,4 +1,5 @@ use anyhow::Context; +use futures::executor::block_on; use std::path::{Path, PathBuf}; use structopt::StructOpt; use summain::ManifestEntry; @@ -8,7 +9,7 @@ fn main() -> anyhow::Result<()> { opt.pathnames[..].sort(); for filename in opt.pathnames.iter() { - let m = manifest(&filename)?; + let m = block_on(manifest(&filename))?; print!("{}", serde_yaml::to_string(&m)?); } @@ -21,6 +22,8 @@ struct Opt { pathnames: Vec<PathBuf>, } -fn manifest(path: &Path) -> anyhow::Result<ManifestEntry> { - ManifestEntry::new(path).with_context(|| format!("{}", path.display())) +async fn manifest(path: &Path) -> anyhow::Result<ManifestEntry> { + ManifestEntry::new(path) + .await + .with_context(|| format!("{}", path.display())) } @@ -60,7 +60,7 @@ impl ManifestEntry { /// caller. This function doesn't query the system for it. /// /// The structure can be serialized using serde. - pub fn new(path: &Path) -> std::io::Result<Self> { + pub async fn new(path: &Path) -> std::io::Result<Self> { let m = symlink_metadata(path)?; let hash = if m.is_file() { Some(file_checksum(path)?) |