#![no_std]
#![doc = include_str!("../README.md")]
#[doc = include_str!("../README.md")]
pub trait ToTrue: Sized {
fn to_true<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R;
fn to_false<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R;
}
impl ToTrue for bool {
fn to_true<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R,
{
if *self {
None
} else {
*self = true;
Some(f())
}
}
fn to_false<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R,
{
if *self {
*self = false;
Some(f())
} else {
None
}
}
}
pub trait InTrue: Sized {
fn in_true<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R;
fn in_false<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R;
}
impl InTrue for bool {
fn in_true<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R,
{
let old = *self;
*self = true;
old.then(f)
}
fn in_false<F, R>(&mut self, f: F) -> Option<R>
where F: FnOnce() -> R,
{
let old = *self;
*self = false;
(!old).then(f)
}
}