-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed184e4
commit b2b4db0
Showing
8 changed files
with
144 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use super::DataError; | ||
use std::path::{Path, PathBuf}; | ||
use uuid::Uuid; | ||
|
||
/// Manages profile data stored on the filesystem. | ||
pub struct Prof { | ||
root: PathBuf, | ||
} | ||
|
||
impl Prof { | ||
pub(super) fn new(root: PathBuf) -> Self { | ||
Self { root } | ||
} | ||
|
||
pub fn list(&self) -> Result<impl Iterator<Item = Result<PathBuf, DataError>> + '_, DataError> { | ||
std::fs::read_dir(&self.root) | ||
.map_err(|e| DataError::ReadDirectory(self.root.clone(), e)) | ||
.map(|iter| List { | ||
iter, | ||
path: &self.root, | ||
}) | ||
} | ||
|
||
pub fn data(&self, id: Uuid) -> PathBuf { | ||
let mut buf = Uuid::encode_buffer(); | ||
let id = id.as_hyphenated().encode_lower(&mut buf); | ||
|
||
self.root.join(id) | ||
} | ||
} | ||
|
||
/// Implementation of [`Iterator`] to enumerate profile directories. | ||
struct List<'a> { | ||
iter: std::fs::ReadDir, | ||
path: &'a Path, | ||
} | ||
|
||
impl<'a> Iterator for List<'a> { | ||
type Item = Result<PathBuf, DataError>; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
self.iter | ||
.next()? | ||
.map_err(|e| DataError::ReadDirectory(self.path.into(), e)) | ||
.map(|i| i.path()) | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters