use std::collections::HashMap;
pub enum ValueOrFn<T> {
Value(T),
Closure(Box<dyn FnOnce() -> T>),
}
pub fn value<T>(input: ValueOrFn<T>) -> T {
match input {
ValueOrFn::Value(val) => val,
ValueOrFn::Closure(f) => f(),
}
}
pub trait IntoValueOrFn<T> {
fn into(self) -> ValueOrFn<T>;
}
impl<T> IntoValueOrFn<T> for T {
fn into(self) -> ValueOrFn<T> {
ValueOrFn::Value(self)
}
}
impl<T, F> IntoValueOrFn<T> for F
where
F: FnOnce() -> T + 'static,
{
fn into(self) -> ValueOrFn<T> {
ValueOrFn::Closure(Box::new(self))
}
}
pub trait IntoCondition {
fn into_bool(self) -> bool;
}
impl IntoCondition for bool {
fn into_bool(self) -> bool {
self
}
}
impl<F> IntoCondition for F
where
F: FnOnce() -> bool,
{
fn into_bool(self) -> bool {
self()
}
}