summaryrefslogtreecommitdiff
path: root/src/fsiter.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-02-03 09:11:49 +0200
committerLars Wirzenius <liw@liw.fi>2021-02-04 09:14:01 +0200
commita2adcb5a90c15b473a2fcf114555443fba8a20ce (patch)
tree7ec36f244daa105b0da774d6705ef736f9135f64 /src/fsiter.rs
parentbf08ea67ca035fc0e78364450599cefff7cd9bc6 (diff)
downloadobnam2-a2adcb5a90c15b473a2fcf114555443fba8a20ce.tar.gz
refactor: have per-module error enums
This means that a function that parses step bindings can't return an error that the document is missing a title. Such an error return would be nonsensical, and we use the Rust type system to prevent it, at a small cost of being a bit verbose. Additional benefit is that the library portion of Obnam doesn't return anyhow::Result values anymore.
Diffstat (limited to 'src/fsiter.rs')
-rw-r--r--src/fsiter.rs17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/fsiter.rs b/src/fsiter.rs
index a40ad34..36693a6 100644
--- a/src/fsiter.rs
+++ b/src/fsiter.rs
@@ -1,4 +1,4 @@
-use crate::fsentry::FilesystemEntry;
+use crate::fsentry::{FilesystemEntry, FsEntryError};
use log::info;
use std::path::Path;
use walkdir::{IntoIter, WalkDir};
@@ -8,6 +8,17 @@ pub struct FsIterator {
iter: IntoIter,
}
+#[derive(Debug, thiserror::Error)]
+pub enum FsIterError {
+ #[error(transparent)]
+ WalkError(#[from] walkdir::Error),
+
+ #[error(transparent)]
+ FsEntryError(#[from] FsEntryError),
+}
+
+pub type FsIterResult<T> = Result<T, FsIterError>;
+
impl FsIterator {
pub fn new(root: &Path) -> Self {
Self {
@@ -17,7 +28,7 @@ impl FsIterator {
}
impl Iterator for FsIterator {
- type Item = Result<FilesystemEntry, anyhow::Error>;
+ type Item = FsIterResult<FilesystemEntry>;
fn next(&mut self) -> Option<Self::Item> {
match self.iter.next() {
None => None,
@@ -30,7 +41,7 @@ impl Iterator for FsIterator {
}
}
-fn new_entry(e: &walkdir::DirEntry) -> anyhow::Result<FilesystemEntry> {
+fn new_entry(e: &walkdir::DirEntry) -> FsIterResult<FilesystemEntry> {
let meta = e.metadata()?;
let entry = FilesystemEntry::from_metadata(e.path(), &meta)?;
Ok(entry)