Struct Host

Source
pub struct Host<T> {
    pub tasks: Vec<JoinHandle<Option<u8>>>,
    /* private fields */
}
Expand description

Meant as the main way of sending commands to plugins. A structure that holds the input ends of the queues to each plugin, as well as the JoinHandles to their tasks.

Fields§

§tasks: Vec<JoinHandle<Option<u8>>>

Implementations§

Source§

impl<T: Sync + Send + 'static> Host<T>

Source

pub const DEFAULT_CHANNEL_CAPACITY: usize = 4usize

By default, plugins will communicate with the host using a queue capable of holding this many Messages.

Source

pub fn new() -> Self

Source

pub fn send(&mut self, message: impl Into<Message<T>>)

Sends a message to all the attached Plugins.

Source

pub fn attach(&mut self, plugin: impl Plugin<T>)

Enables a Plugin by attaching it to the Host: a channel is built, the input is given to the host; a task running the Plugin’s handle_message method on every Message sent over the channel is spawned, and the JoinHandle to this task is added to the host’s handles.

Source

pub fn attach_with_capacity(&mut self, plugin: impl Plugin<T>, capacity: usize)

Like attach, but allows you to choose your own channel capacity.

Source

pub fn end(&mut self) -> Vec<Result<Option<u8>>>

Drops every channel end, closing them, then waits for all plugins to finish processing the remaining messages.

Trait Implementations§

Source§

impl<T> Drop for Host<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Host<T>

§

impl<T> !RefUnwindSafe for Host<T>

§

impl<T> Send for Host<T>
where T: Sync + Send,

§

impl<T> Sync for Host<T>
where T: Sync + Send,

§

impl<T> Unpin for Host<T>

§

impl<T> !UnwindSafe for Host<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.