use core::fmt::Debug;
use crate::{
executors::{Executor, ExitKind, HasObservers},
observers::UsesObservers,
state::{HasExecutions, UsesState},
Error,
};
#[derive(Debug)]
pub struct CombinedExecutor<A, B> {
primary: A,
secondary: B,
}
impl<A, B> CombinedExecutor<A, B> {
pub fn new<EM, Z>(primary: A, secondary: B) -> Self
where
A: Executor<EM, Z>,
B: Executor<EM, Z, State = A::State>,
EM: UsesState<State = A::State>,
Z: UsesState<State = A::State>,
{
Self { primary, secondary }
}
pub fn primary(&mut self) -> &mut A {
&mut self.primary
}
pub fn secondary(&mut self) -> &mut B {
&mut self.secondary
}
}
impl<A, B, EM, Z> Executor<EM, Z> for CombinedExecutor<A, B>
where
A: Executor<EM, Z>,
B: Executor<EM, Z, State = A::State>,
EM: UsesState<State = A::State>,
EM::State: HasExecutions,
Z: UsesState<State = A::State>,
{
fn run_target(
&mut self,
fuzzer: &mut Z,
state: &mut Self::State,
mgr: &mut EM,
input: &Self::Input,
) -> Result<ExitKind, Error> {
*state.executions_mut() += 1;
let ret = self.primary.run_target(fuzzer, state, mgr, input);
self.primary.post_run_reset();
self.secondary.post_run_reset();
ret
}
}
impl<A, B> UsesState for CombinedExecutor<A, B>
where
A: UsesState,
{
type State = A::State;
}
impl<A, B> UsesObservers for CombinedExecutor<A, B>
where
A: UsesObservers,
{
type Observers = A::Observers;
}
impl<A, B> HasObservers for CombinedExecutor<A, B>
where
A: HasObservers,
{
#[inline]
fn observers(&self) -> &Self::Observers {
self.primary.observers()
}
#[inline]
fn observers_mut(&mut self) -> &mut Self::Observers {
self.primary.observers_mut()
}
}