Trait Node

Source
pub trait Node<C: Ctx = ()>:
    Send
    + 'static
    + Sized {
    // Required methods
    fn endpoint(&self) -> Option<&Endpoint>;
    fn spawn(
        context: &mut SpawnContext<'_, C>,
    ) -> impl Future<Output = Result<Self>> + Send;

    // Provided methods
    fn shutdown(&mut self) -> impl Future<Output = Result<()>> + Send + '_ { ... }
    fn spawn_dyn<'a>(
        context: &'a mut SpawnContext<'_, C>,
    ) -> Pin<Box<dyn Future<Output = Result<BoxNode<C>>> + Send + 'a>> { ... }
    fn node_label(&self, _context: &SpawnContext<'_, C>) -> Option<String> { ... }
}
Expand description

Trait for simulation node implementations.

Provides basic functionality for nodes including optional endpoint access and cleanup on shutdown.

To use a node in a simulation, implement this trait for your type and provide an async spawn function. Add the node to a simulation with NodeBuilder::new(round_fn) and Builder::spawn(...).

Required Methods§

Source

fn endpoint(&self) -> Option<&Endpoint>

Returns a reference to this node’s endpoint, if any.

Source

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

Spawns a new instance of this node type.

§Errors

Returns an error if the node fails to initialize properly.

Provided Methods§

Source

fn shutdown(&mut self) -> impl Future<Output = Result<()>> + Send + '_

Shuts down this node, performing any necessary cleanup.

The default implementation does nothing and returns success.

§Errors

Returns an error if shutdown fails.

Source

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

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 node_label(&self, _context: &SpawnContext<'_, C>) -> Option<String>

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§