[][src]Struct apex::Slot

pub struct Slot<T: Send + Sync + Copy + 'static> { /* fields omitted */ }

Slot component of the Signals and Slots implementation. This uses mpsc channels provided by 'crossbeam' internally for communication between this and connected 'Signal's

Implementations

impl<T: Send + Sync + Copy + 'static> Slot<T>[src]

pub fn new(poll_time: Duration, update_interval: Duration) -> Slot<T>[src]

Creates a new Slot of the type T, with the given polling time and update_interval.

Arguments

  • 'poll-time' - the length of time the slot should poll for signals every update interval
  • 'update-interval' - the length of time the slot should sleep between polling for signals

Returns

  • a new Slot

pub fn connect(&self, signal: &mut Signal<T>)[src]

Connects the given Signal to this Slot

Arguments

  • 'signal' - the signal to connect

pub fn open(
    &mut self,
    callback: impl FnMut(T) + 'static + Send + Sync
) -> Result<(), SlotError>
[src]

Opens this slot to receiving signals

This spawns a new 'event loop' thread for the slot to poll for signals and call the 'callback' closure upon receiving them. If the Slot is already open, nothing is done and SlotError::AlradyOpen is returned.

Arguments

  • 'callback' - the closure to call upon receiving a signal. Because this is called on a separate thread, objects captured by the closer must be threadsafe (Send + Sync)

Returns

  • success - Ok(())
  • failure - Err(SlotError::AlreadyOpen)

pub fn close(self) -> Result<(), SlotError>[src]

Closes the Slot, so it can no longer receive Signals

This joins the internal 'event loop' thread. If the Slot wasn't open, SlotError::NotOpened is returned. If the Slot was already closed, SlotError::AlreadyClosed is returned. If there was an error joining the thread, SlotError::ThreadJoin(Box<dyn std::any::Any + Send>) is returned. Otherwise, Ok(()) is returned.

Returns

  • success - Ok(())
  • failure - SlotError

Auto Trait Implementations

impl<T> !RefUnwindSafe for Slot<T>

impl<T> Send for Slot<T>

impl<T> Sync for Slot<T>

impl<T> Unpin for Slot<T>

impl<T> !UnwindSafe for Slot<T>

Blanket Implementations

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

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

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

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

impl<T, U> Into<U> for T where
    U: From<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.