Trait Spawn

Source
pub trait Spawn<D: SetupData = ()>: Node + 'static {
    // Required method
    fn spawn(
        context: &mut SpawnContext<'_, D>,
    ) -> impl Future<Output = Result<Self>> + Send
       where Self: Sized;

    // Provided methods
    fn spawn_dyn<'a>(
        context: &'a mut SpawnContext<'a, D>,
    ) -> Pin<Box<dyn Future<Output = Result<BoxNode>> + Send + 'a>>
       where Self: Sized { ... }
    fn builder(
        round_fn: impl for<'a> AsyncCallback<'a, Self, RoundContext<'a, D>, Result<bool>>,
    ) -> NodeBuilder<Self, D>
       where Self: Sized { ... }
}
Expand description

Trait for types that can be spawned as simulation nodes.

This trait is generic over D: SetupData, which is the type returned from the user-defined setup function (see Builder::with_setup). If not using the setup step, D defaults to the unit type ().

Implement this trait on your node type to be able to spawn the node in a simulation context. The only required method is Spawn::spawn, which must return your spawned node.

Required Methods§

Source

fn spawn( context: &mut SpawnContext<'_, D>, ) -> impl Future<Output = Result<Self>> + Send
where Self: Sized,

Spawns a new instance of this node type.

§Errors

Returns an error if the node fails to initialize properly.

Provided Methods§

Source

fn spawn_dyn<'a>( context: &'a mut SpawnContext<'a, D>, ) -> Pin<Box<dyn Future<Output = Result<BoxNode>> + Send + 'a>>
where Self: Sized,

Spawns a new instance as a dynamically-typed node.

This calls spawn and boxes the result.

§Errors

Returns an error if the node fails to initialize properly.

Source

fn builder( round_fn: impl for<'a> AsyncCallback<'a, Self, RoundContext<'a, D>, Result<bool>>, ) -> NodeBuilder<Self, D>
where Self: Sized,

Creates a new builder for this node type with the given round function.

The round function will be called each simulation round and should return Ok(true) to continue or Ok(false) to stop early.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§