//! A `ShadowExecutor` wraps an executor to have shadow observer that will not be considered by the feedbacks and the manager use core::fmt::{self, Debug, Formatter}; use crate::{ executors::{Executor, ExitKind, HasObservers}, observers::{ObserversTuple, UsesObservers}, state::UsesState, Error, }; /// A [`ShadowExecutor`] wraps an executor and a set of shadow observers pub struct ShadowExecutor { /// The wrapped executor executor: E, /// The shadow observers shadow_observers: SOT, } impl Debug for ShadowExecutor where E: UsesState + Debug, SOT: ObserversTuple + Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("ShadowExecutor") .field("executor", &self.executor) .field("shadow_observers", &self.shadow_observers) .finish() } } impl ShadowExecutor where E: HasObservers + Debug, SOT: ObserversTuple + Debug, { /// Create a new `ShadowExecutor`, wrapping the given `executor`. pub fn new(executor: E, shadow_observers: SOT) -> Self { Self { executor, shadow_observers, } } /// The shadow observers are not considered by the feedbacks and the manager, mutable #[inline] pub fn shadow_observers(&self) -> &SOT { &self.shadow_observers } /// The shadow observers are not considered by the feedbacks and the manager, mutable #[inline] pub fn shadow_observers_mut(&mut self) -> &mut SOT { &mut self.shadow_observers } } impl Executor for ShadowExecutor where E: Executor + HasObservers, SOT: ObserversTuple, EM: UsesState, Z: UsesState, { fn run_target( &mut self, fuzzer: &mut Z, state: &mut Self::State, mgr: &mut EM, input: &Self::Input, ) -> Result { self.executor.run_target(fuzzer, state, mgr, input) } } impl UsesState for ShadowExecutor where E: UsesState, { type State = E::State; } impl UsesObservers for ShadowExecutor where E: UsesObservers, { type Observers = E::Observers; } impl HasObservers for ShadowExecutor where E: HasObservers, SOT: ObserversTuple, { #[inline] fn observers(&self) -> &Self::Observers { self.executor.observers() } #[inline] fn observers_mut(&mut self) -> &mut Self::Observers { self.executor.observers_mut() } }