Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoikey committed Feb 20, 2024
1 parent b3cb545 commit 02ad063
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt::{Debug, Display, Formatter};
#[derive(Debug)]
pub struct Error<T> {
message: String,
pub target: T,
target: T,
}

impl<T> Error<T> {
Expand All @@ -14,6 +14,10 @@ impl<T> Error<T> {
target,
}
}

pub fn into_target(self) -> T {
self.target
}
}

impl<T> Display for Error<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/rule/composer/not.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
fn validate(target: Self::Item) -> Result<Self::Item, Error<Self::Item>> {
let bounded_rule = move |t: T| match RULE::validate(t) {
Ok(t) => Err(Error::new("Target satisfies the rule", t)),
Err(e) => Ok(e.target),
Err(e) => Ok(e.into_target()),
};
bounded_rule(target)
}
Expand Down
3 changes: 2 additions & 1 deletion src/rule/composer/or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ where
type Item = T;

fn validate(target: Self::Item) -> Result<Self::Item, Error<Self::Item>> {
let bounded_rule = move |t: T| RULE1::validate(t).or_else(|e| RULE2::validate(e.target));
let bounded_rule =
move |t: T| RULE1::validate(t).or_else(|e| RULE2::validate(e.into_target()));
bounded_rule(target)
}
}
Expand Down

0 comments on commit 02ad063

Please sign in to comment.