use crate :: { import::* };
pub enum Filter<Event>
where Event: Clone + 'static + Send ,
{
Pointer( fn(&Event) -> bool ),
Closure( Box<dyn FnMut(&Event) -> bool + Send> ),
}
impl<Event> Filter<Event> where Event: Clone + 'static + Send
{
pub(crate) fn call( &mut self, evt: &Event ) -> bool
{
match self
{
Self::Pointer(f) => f(evt),
Self::Closure(f) => f(evt),
}
}
}
impl<Event> fmt::Debug for Filter<Event> where Event: Clone + 'static + Send
{
fn fmt( &self, f: &mut fmt::Formatter<'_> ) -> fmt::Result
{
match self
{
Self::Pointer(_) => write!( f, "pharos::Filter<{}>::Pointer(_)", type_name::<Event>() ),
Self::Closure(_) => write!( f, "pharos::Filter<{}>::Closure(_)", type_name::<Event>() ),
}
}
}
#[ cfg( test ) ]
mod tests
{
use super::*;
#[test]
fn debug()
{
let f = Filter::Pointer( |b| *b );
let g = Filter::Closure( Box::new( |b| *b ) );
assert_eq!( "pharos::Filter<bool>::Pointer(_)", &format!( "{:?}", f ) );
assert_eq!( "pharos::Filter<bool>::Closure(_)", &format!( "{:?}", g ) );
}
}