pub trait PushOwned<T> {
fn push(self, val: T) -> Self;
fn try_push(self, val: Option<T>) -> Self
where
Self: Sized,
{
if let Some(val) = val {
self.push(val)
} else {
self
}
}
}
pub trait SetOwned<T> {
fn set(self, val: T) -> Self;
fn try_set(self, val: Option<T>) -> Self
where
Self: Sized,
{
if let Some(val) = val {
self.set(val)
} else {
self
}
}
}
pub trait DeclarativeConfig: Sized {
fn config(self, block: impl FnOnce(Self) -> Self) -> Self {
block(self)
}
fn config_if(self, condition: bool, block: impl FnOnce(Self) -> Self) -> Self {
if condition {
self.config(block)
} else {
self
}
}
fn config_if_else(
self,
condition: bool,
block: impl FnOnce(Self) -> Self,
else_block: impl FnOnce(Self) -> Self,
) -> Self {
if condition {
self.config(block)
} else {
self.config(else_block)
}
}
}