From b52f2f38d77cbe9c791c2eabb45cdf8d79119d7b Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Mon, 22 Dec 2025 03:55:48 +0300 Subject: [PATCH] boolext --- core/src/errors/ext.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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