use super::*;
#[derive(Clone, Debug, Default)]
pub struct RefCell<M> {
mutator: M,
}
pub fn ref_cell<M>(mutator: M) -> RefCell<M> {
RefCell { mutator }
}
impl<M, T> Mutate<core::cell::RefCell<T>> for RefCell<M>
where
M: Mutate<T>,
{
#[inline]
fn mutate(&mut self, c: &mut Candidates, value: &mut core::cell::RefCell<T>) -> Result<()> {
self.mutator.mutate(c, value.get_mut())
}
#[inline]
fn mutation_count(
&self,
value: &core::cell::RefCell<T>,
shrink: bool,
) -> core::option::Option<u32> {
self.mutator.mutation_count(&*value.borrow(), shrink)
}
}
impl<M, T> Generate<core::cell::RefCell<T>> for RefCell<M>
where
M: Generate<T>,
{
#[inline]
fn generate(&mut self, ctx: &mut Context) -> Result<core::cell::RefCell<T>> {
Ok(core::cell::RefCell::new(self.mutator.generate(ctx)?))
}
}
impl<T> DefaultMutate for core::cell::RefCell<T>
where
T: DefaultMutate,
{
type DefaultMutate = RefCell<T::DefaultMutate>;
}