use alloc::boxed::Box;
use witnessed::Witnessed;
pub struct V01;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct V01Error;
pub fn prove_v01_f32(value: &f32) -> Result<V01, V01Error> {
(0.0..=1.0).contains(value).then_some(V01).ok_or(V01Error)
}
pub fn prove_v01_f64(value: &f64) -> Result<V01, V01Error> {
(0.0..=1.0).contains(value).then_some(V01).ok_or(V01Error)
}
pub trait Measure<Ctx: ?Sized>: Send + Sync {
type Output;
fn measure(&self, ctx: &Ctx) -> Self::Output;
}
pub trait Map01F32: Send + Sync {
type Input;
fn map(&self, value: Self::Input) -> Witnessed<f32, V01>;
}
pub trait Map01F64: Send + Sync {
type Input;
fn map(&self, value: Self::Input) -> Witnessed<f64, V01>;
}
pub trait EvalF64<Ctx: ?Sized>: Send + Sync {
fn eval(&self, ctx: &Ctx) -> f64;
}
impl<Ctx, E> EvalF64<Ctx> for Box<E>
where
Ctx: ?Sized,
E: EvalF64<Ctx> + ?Sized,
{
#[inline]
fn eval(&self, ctx: &Ctx) -> f64 {
self.as_ref().eval(ctx)
}
}
pub trait EvalF32<Ctx: ?Sized>: Send + Sync {
fn eval(&self, ctx: &Ctx) -> f32;
}
impl<Ctx, E> EvalF32<Ctx> for Box<E>
where
Ctx: ?Sized,
E: EvalF32<Ctx> + ?Sized,
{
#[inline]
fn eval(&self, ctx: &Ctx) -> f32 {
self.as_ref().eval(ctx)
}
}