use super::*;
use alloc::borrow::ToOwned;
#[derive(Clone, Debug, Default)]
pub struct CowMutator<M> {
mutator: M,
}
pub fn cow<M>(mutator: M) -> CowMutator<M> {
CowMutator { mutator }
}
impl<'a, M, B> Mutate<alloc::borrow::Cow<'a, B>> for CowMutator<M>
where
B: ToOwned + ?Sized,
M: Mutate<<B as ToOwned>::Owned>,
{
#[inline]
fn mutate(&mut self, c: &mut Candidates, value: &mut alloc::borrow::Cow<'a, B>) -> Result<()> {
self.mutator.mutate(c, value.to_mut())
}
}
impl<'a, M, B> Generate<alloc::borrow::Cow<'a, B>> for CowMutator<M>
where
B: ToOwned + ?Sized,
M: Generate<<B as ToOwned>::Owned>,
{
#[inline]
fn generate(&mut self, ctx: &mut Context) -> Result<alloc::borrow::Cow<'a, B>> {
Ok(alloc::borrow::Cow::Owned(self.mutator.generate(ctx)?))
}
}
impl<'a, B> DefaultMutate for alloc::borrow::Cow<'a, B>
where
B: ToOwned + ?Sized,
<B as ToOwned>::Owned: DefaultMutate,
<<B as ToOwned>::Owned as DefaultMutate>::DefaultMutate: Generate<<B as ToOwned>::Owned>,
{
type DefaultMutate = CowMutator<<<B as ToOwned>::Owned as DefaultMutate>::DefaultMutate>;
}