diff --git a/core/src/errors/ext.rs b/core/src/errors/ext.rs index 62e7bbf..e783f4c 100644 --- a/core/src/errors/ext.rs +++ b/core/src/errors/ext.rs @@ -44,6 +44,29 @@ impl ResultExt for Result { } } +pub trait BoolExt: Sized { + fn true_or(self, err: E) -> Result<(), E>; + fn false_or(self, err: E) -> Result<(), E>; +} + +impl BoolExt for bool { + fn true_or(self, err: E) -> Result<(), E> { + if self { + Ok(()) + } else { + Err(err) + } + } + + fn false_or(self, err: E) -> Result<(), E> { + if self { + Err(err) + } else { + Ok(()) + } + } +} + pub trait ErrExt: Sized { #[track_caller] fn aux(self) -> Aux