[][src]Struct pharos::ObserveConfig

pub struct ObserveConfig<Event> where
    Event: Clone + 'static + Send
{ /* fields omitted */ }

Configuration for your event stream, passed to Observable::observe when subscribing. This let's you choose the type of channel and let's you set a filter to ignore certain events.

use pharos::*;

// We choose event type usize for simplicity. You choose whatever type you want here,
// see the bounds on the Event type parameter throughout this library.
//
let mut pharos = Pharos::<usize>::default();

// Use defaults, unbounded channel and no filter.
//
pharos.observe( ObserveConfig::default() );

// Use bounded channel and defaults for other options.
//
pharos.observe( Channel::Bounded(5).into() );

// Use a filter and defaults for other options.
// Will only receive events if they are bigger than three.
//
pharos.observe( Filter::Pointer( |evt| *evt > 3 ).into() );

// Set both channel and filter. Note you can only set one filter per observable.
//
let opts = ObserveConfig::default()

   .channel( Channel::Bounded( 5 ) )
   .filter ( |evt| *evt > 3        )
;

pharos.observe( opts );

Methods

impl<Event> ObserveConfig<Event> where
    Event: Clone + 'static + Send
[src]

pub fn channel(self, channel: Channel) -> Self[src]

Choose which channel implementation to use for your event stream.

pub fn filter(self, filter: fn(_: &Event) -> bool) -> Self[src]

Filter your event stream with a predicate that is a fn pointer. You can only set one filter per observable.

pub fn filter_boxed(
    self,
    filter: impl FnMut(&Event) -> bool + Send + 'static
) -> Self
[src]

Filter your event stream with a predicate that is a closure that captures environment. It is preferred to use filter if you can as this will box the closure. You can only set one filter per observable.

Trait Implementations

impl<Event> Default for ObserveConfig<Event> where
    Event: Clone + 'static + Send
[src]

Create a default configuration:

  • no filter
  • an unbounded channel

impl<Event> From<Channel> for ObserveConfig<Event> where
    Event: Clone + 'static + Send
[src]

Create a ObserveConfig from a Channel, getting default values for other options.

impl<Event> From<Filter<Event>> for ObserveConfig<Event> where
    Event: Clone + 'static + Send
[src]

Create a ObserveConfig from a Filter, getting default values for other options.

impl<Event: Debug> Debug for ObserveConfig<Event> where
    Event: Clone + 'static + Send
[src]

Auto Trait Implementations

impl<Event> Send for ObserveConfig<Event>

impl<Event> Unpin for ObserveConfig<Event>

impl<Event> !Sync for ObserveConfig<Event>

impl<Event> !UnwindSafe for ObserveConfig<Event>

impl<Event> !RefUnwindSafe for ObserveConfig<Event>

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,