Enum Agent

Source
pub enum Agent<T = ()> {
    Stop(T),
    Continue(T),
}
Expand description

See the crate’s main documentation for a description of what an Agent is.

The Agent is also an enum that can be used to control the Agent when using Handle::call.

Variants§

§

Stop(T)

Stop the agent.

§

Continue(T)

Continue running the agent.

Implementations§

Source§

impl<T> Agent<T>

Source

pub fn spawn_thread_named<F>( initial_state: F, name: String, ) -> Result<Handle<T>>
where F: FnOnce() -> T + Send + 'static, T: 'static,

Spawns an agent that will manage the state returned by the initial_state function in its own thread.

This function is identical to Agent::spawn_thread, except that it allows for you to name the thread.

Source

pub fn spawn_thread<F>(initial_state: F) -> Result<Handle<T>>
where F: FnOnce() -> T + Send + 'static, T: 'static,

Spawns an agent that will manage the state returned by initial_state in its own thread.

The thread will be named after the type returned by initial_state.

Source

pub fn spawn_task<F>(initial_state: F) -> Handle<T>
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,

Spawns an agent that will manage the state returned by initial_state a task using tokio::task::spawn.

This function must be called from the context of a Tokio runtime.

§Panics

Panics if called from outside of the Tokio runtime.

Source

pub fn spawn_local_task<F>(initial_state: F) -> Handle<T>
where F: FnOnce() -> T + 'static, T: 'static,

Spawns an agent that will manage the state returned by initial_state in a local task using tokio::task::spawn_local.

The agent will be run on the same thread that called spawn_local. This may only be called from the context of a local task set.

§Panics

Panics if called outside of a local task set.

Auto Trait Implementations§

§

impl<T> Freeze for Agent<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Agent<T>
where T: RefUnwindSafe,

§

impl<T> Send for Agent<T>
where T: Send,

§

impl<T> Sync for Agent<T>
where T: Sync,

§

impl<T> Unpin for Agent<T>
where T: Unpin,

§

impl<T> UnwindSafe for Agent<T>
where T: UnwindSafe,

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.