fire event macro
This commit is contained in:
parent
6b6e2a8907
commit
0f7bb3a4dd
@ -16,9 +16,46 @@ pub trait EventManager {
|
||||
} */
|
||||
|
||||
/// Fire an Event
|
||||
fn fire<E: Event>(&mut self) -> Result<(), AflError>;
|
||||
fn fire<E: Event>(&mut self, event: E) -> Result<(), AflError>;
|
||||
|
||||
/// Lookup for incoming events and process them.
|
||||
/// Return the number of processes events or an error
|
||||
fn lookup(&mut self) -> Result<usize, AflError>;
|
||||
}
|
||||
|
||||
// e.g. fire_event!(manager, MyEvent, myparam1, ...)
|
||||
macro_rules! fire_event {
|
||||
($manager:expr, $event:ty, $( $x:expr ),+ ) => {
|
||||
{
|
||||
if $manager.enabled::<$event>() {
|
||||
$manager.fire(<$event>::new($( $x ),*))
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
};
|
||||
($manager:expr, $event:ty) => {
|
||||
{
|
||||
if $manager.enabled::<$event>() {
|
||||
$manager.fire(<$event>::new())
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
#[derive(Debug)]
|
||||
pub struct MyEvent {}
|
||||
impl Event for MyEvent {}
|
||||
impl MyEvent {
|
||||
pub fn new() -> Self {
|
||||
MyEvent {}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn my_event_test<M: EventManager>(manager: &mut M) {
|
||||
fire_event!(manager, MyEvent).unwrap();
|
||||
}
|
||||
*/
|
||||
|
@ -5,6 +5,7 @@ extern crate alloc;
|
||||
|
||||
pub mod corpus;
|
||||
pub mod engines;
|
||||
pub mod events;
|
||||
pub mod executors;
|
||||
pub mod feedbacks;
|
||||
pub mod generators;
|
||||
|
Loading…
x
Reference in New Issue
Block a user