Introduce BoolMutator (#2926)

This commit is contained in:
Valentin Huber 2025-02-01 21:24:24 +01:00 committed by GitHub
parent 6648bc90d2
commit 6243b684f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -407,3 +407,22 @@ impl Named for NopMutator {
&Cow::Borrowed("NopMutator")
}
}
/// [`Mutator`] that flips a boolean value.
///
/// Mostly useful in combination with [`mapping::MappingMutator`]s.
#[derive(Debug)]
pub struct BoolMutator;
impl<S> Mutator<bool, S> for BoolMutator {
fn mutate(&mut self, _state: &mut S, input: &mut bool) -> Result<MutationResult, Error> {
*input = !*input;
Ok(MutationResult::Mutated)
}
}
impl Named for BoolMutator {
fn name(&self) -> &Cow<'static, str> {
&Cow::Borrowed("BoolMutator")
}
}