Skip to main content

Node

Trait Node 

Source
pub trait Node:
    Send
    + Sized
    + 'static {
    type Builder: NodeBuilder<Self>;
    type Backend: StorageBackend;
    type Error: Error;

    // Required methods
    fn stop<'async_trait>(
        self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
       where Self: 'async_trait;
    fn spawn<W, G, F>(&mut self, g: G)
       where W: Worker<Self>,
             G: FnOnce(Receiver<()>) -> F,
             F: Future<Output = ()> + Send + 'static;
    fn worker<W>(&self) -> Option<&W>
       where W: Worker<Self> + Send + Sync;
    fn register_resource<R: Any + Send + Sync>(&mut self, res: R);
    fn remove_resource<R: Any + Send + Sync>(&mut self) -> Option<R>;
    fn resource<R: Any + Send + Sync>(&self) -> ResourceHandle<R>;

    // Provided methods
    fn info(&self) -> ResourceHandle<NodeInfo> { ... }
    fn storage(&self) -> ResourceHandle<Self::Backend> { ... }
    fn bus(&self) -> ResourceHandle<Bus<'static>> { ... }
}
Expand description

A trait representing a node framework through which node workers may communicate.

Required Associated Types§

Source

type Builder: NodeBuilder<Self>

The builder type used to create instances of this node.

Source

type Backend: StorageBackend

The storage backend used by this node.

Source

type Error: Error

The type of errors that may be emitted as a result of the build process.

Required Methods§

Source

fn stop<'async_trait>( self, ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,

Stop the node, ending the execution of all workers in a timely manner.

Source

fn spawn<W, G, F>(&mut self, g: G)
where W: Worker<Self>, G: FnOnce(Receiver<()>) -> F, F: Future<Output = ()> + Send + 'static,

Spawn a new node task associated with the given worker.

The task will be shut down with the worker to preserve topological worker ordering.

Source

fn worker<W>(&self) -> Option<&W>
where W: Worker<Self> + Send + Sync,

Get a reference to the state of a worker.

Source

fn register_resource<R: Any + Send + Sync>(&mut self, res: R)

Register a new resource with the node such that other workers may access it via Node::resource.

Source

fn remove_resource<R: Any + Send + Sync>(&mut self) -> Option<R>

Attempt to remove a resource from the node, returning None if no such resource was registered with the node.

Source

fn resource<R: Any + Send + Sync>(&self) -> ResourceHandle<R>

Obtain an owning handle to a node resource.

Provided Methods§

Source

fn info(&self) -> ResourceHandle<NodeInfo>

Obtain an owning handle to the node’s info.

Source

fn storage(&self) -> ResourceHandle<Self::Backend>

Obtain an owning handle to the node’s storage backend.

Source

fn bus(&self) -> ResourceHandle<Bus<'static>>

Obtain an owning handle to the node’s event bus.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§