use crate::*;
use std::ops::*;
#[derive(Copy, Clone, GcCompat)]
pub struct Nondet<T>(pub(crate) T);
pub fn pick<T: Obj>(distr: impl Distribution<T>, f: impl Fn(T) -> bool) -> crate::Nondet<T> {
let mut rng = rand::thread_rng();
for _ in 0..50 {
let s = distr.sample(&mut rng);
if f(s) {
return Nondet(s);
}
}
panic!("Timeout! `pick` could not find a valid value.");
}
pub enum NondetResidual {}
pub fn predict<T>(_f: impl Fn(T) -> bool) -> crate::Nondet<T> { unimplemented!() }
impl<T> Try for Nondet<T> {
type Output = T;
type Residual = NondetResidual;
fn from_output(output: Self::Output) -> Self {
Nondet(output)
}
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
ControlFlow::Continue(self.0)
}
}
impl<T> FromResidual<NondetResidual> for Nondet<T> {
fn from_residual(residual: NondetResidual) -> Self {
match residual {}
}
}
impl<T> Residual<T> for NondetResidual {
type TryType = Nondet<T>;
}