[−][src]Enum pharos::Filter
Predicate for filtering events. This is an enum because closures that capture variables from their environment need to be boxed. More often than not, an event will be a simple enum and the predicate will just match on the variant, so it would be wasteful to impose boxing in those cases, hence there is a function pointer variant which does not require boxing. This should be preferred where possible.
use pharos::*; let a = 5; // This closure captures the a variable from it's environment. // We can still use it as a filter by boxing it with `closure`. // // Note: it depends on the circumstances, but often enough, we need to // annotate the type of the event parameter to the predicate. // // For this example we use bool as event type for simplicity, but it works // just the same if that's an enum. // let predicate = move |_: &bool| { a; true }; let filter = Filter::<bool>::closure( predicate ); // This one does not capture anything, so it can be stored as a function pointer // without boxing. // let predicate = move |_: &bool| { true }; let filter = Filter::<bool>::pointer( predicate ); // You can also use actual functions as filters. // fn predicate_function( event: &bool ) -> bool { true } let filter = Filter::<bool>::pointer( predicate_function );
Variants
A function pointer to use to filter events.
A boxed closure to use to filter events.
Methods
impl<Event> Filter<Event> where
Event: Clone + 'static + Send,
[src]
Event: Clone + 'static + Send,
pub fn closure<F>(predicate: F) -> Self where
F: FnMut(&Event) -> bool + Send + 'static,
[src]
F: FnMut(&Event) -> bool + Send + 'static,
Construct a filter from a closure that captures something from it's environment. This will be boxed and stored under the Filter::Closure variant. To avoid boxing, do not capture any variables from the environment and use Filter::pointer.
pub fn pointer(predicate: fn(_: &Event) -> bool) -> Self
[src]
Construct a filter from a function pointer to a predicate.
Trait Implementations
impl<Event> From<Filter<Event>> for ObserveConfig<Event> where
Event: Clone + 'static + Send,
[src]
Event: Clone + 'static + Send,
Create a ObserveConfig from a Filter, getting default values for other options.
impl<Event> Debug for Filter<Event> where
Event: Clone + 'static + Send,
[src]
Event: Clone + 'static + Send,
Auto Trait Implementations
impl<Event> Send for Filter<Event>
impl<Event> Unpin for Filter<Event>
impl<Event> !Sync for Filter<Event>
impl<Event> !UnwindSafe for Filter<Event>
impl<Event> !RefUnwindSafe for Filter<Event>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,