Skip to main content

Runnable

Trait Runnable 

Source
pub trait Runnable {
    // Provided method
    fn run<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = SimResult> + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
}
Expand description

The Runnable trait defines any active functionality that is spawned by a component.

Components with no independent async behavior can use the default implementation. Active components need to override run. Because the executor is single-threaded, active components normally share state through Rc, RefCell, and Cell instead of Arc or locks. Ports are often stored as RefCell<Option<...>>: setup code connects them through &self, and run takes ownership of them for the lifetime of the spawned task.

The #[async_trait(?Send)] decorator keeps the trait usable through dyn Runnable and produces futures suitable for the single-threaded executor. A basic implementation of the trait looks like:

#[async_trait(?Send)]
pub trait Runnable {
    async fn run(&self) -> SimResult {
        Ok(())
    }
}

A default implementation is provided for any component that doesn’t have any active behaviour.

Provided Methods§

Source

fn run<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = SimResult> + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Provides the method that defines the active element of this component.

Default implementation is to do nothing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§