diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-12-07 13:31:34 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-12-07 13:31:34 +0100 |
commit | d1badf8f02908478f50558e68f2a08b0e577979e (patch) | |
tree | c7a468c530a0cb471b9d0833b96d7b37dc940d59 /src/filestore/path.rs | |
parent | 17e907e1863d8fecf25edac01d81d595b45a9b69 (diff) |
Remove AsRef<Path> for FullArtifactPath impl
This patch removes the AsRef<Path> implementation for FullArtifactPath,
to make everything more explicit.
It also alters the FileStoreImpl implementation to contain a map of
ArtifactPath -> Artifact, rather than PathBuf -> Artifact, which is also
more type-safe than before this way.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'src/filestore/path.rs')
-rw-r--r-- | src/filestore/path.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/filestore/path.rs b/src/filestore/path.rs index 31e4bb0..0eba9ea 100644 --- a/src/filestore/path.rs +++ b/src/filestore/path.rs @@ -2,8 +2,10 @@ use std::path::Path; use std::path::PathBuf; use std::ffi::OsStr; +use anyhow::anyhow; use anyhow::Error; use anyhow::Result; +use anyhow::Context; #[derive(Debug)] pub struct StoreRoot(PathBuf); @@ -41,7 +43,7 @@ impl AsRef<Path> for StoreRoot { } -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct ArtifactPath(PathBuf); impl ArtifactPath { @@ -73,17 +75,15 @@ impl ArtifactPath { #[derive(Clone, Debug, PartialEq, Eq)] pub struct FullArtifactPath(PathBuf); -impl AsRef<Path> for FullArtifactPath { - fn as_ref(&self) -> &Path { - self.0.as_ref() - } -} - impl FullArtifactPath { pub (in crate::filestore) fn is_dir(&self) -> bool { self.0.is_dir() } + pub (in crate::filestore) fn as_path(&self) -> &Path { + self.0.as_ref() + } + pub (in crate::filestore) fn is_file(&self) -> bool { self.0.is_file() } @@ -91,5 +91,13 @@ impl FullArtifactPath { pub fn display(&self) -> std::path::Display { self.0.display() } + + pub async fn read(self) -> Result<Vec<u8>> { + tokio::fs::read(&self.0) + .await + .map(Vec::from) + .with_context(|| anyhow!("Reading artifact from path {}", self.0.display())) + .map_err(Error::from) + } } |