boolext
This commit is contained in:
parent
a67e3d1d8c
commit
b52f2f38d7
1 changed files with 23 additions and 0 deletions
|
|
@ -44,6 +44,29 @@ impl<O, E> ResultExt for Result<O, E> {
|
|||
}
|
||||
}
|
||||
|
||||
pub trait BoolExt: Sized {
|
||||
fn true_or<E>(self, err: E) -> Result<(), E>;
|
||||
fn false_or<E>(self, err: E) -> Result<(), E>;
|
||||
}
|
||||
|
||||
impl BoolExt for bool {
|
||||
fn true_or<E>(self, err: E) -> Result<(), E> {
|
||||
if self {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
|
||||
fn false_or<E>(self, err: E) -> Result<(), E> {
|
||||
if self {
|
||||
Err(err)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ErrExt: Sized {
|
||||
#[track_caller]
|
||||
fn aux(self) -> Aux
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue