This commit is contained in:
Aleksandr 2025-12-22 03:55:48 +03:00
parent a67e3d1d8c
commit b52f2f38d7

View file

@ -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