Struct Slot

Source
pub struct Slot<T: Send + Sync + Copy + 'static> { /* private fields */ }
Expand description

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§

Source§

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

Source

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

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
Source

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

Connects the given Signal to this Slot

§Arguments
  • ‘signal’ - the signal to connect
Source

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

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)
Source

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

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> Freeze for Slot<T>

§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.