pub trait NodeLifecycle:
Send
+ Sync
+ 'static {
const NAME: Option<&'static str> = None;
// Required methods
fn pre_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StartContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn on_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StartContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn run<'life0, 'async_trait>(
&'life0 self,
ctx: RunContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn on_stop<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StopContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn post_stop<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StopContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
}Expand description
The business-logic core of a service.
Implementors own all in-memory state (stores, pools, caches) and expose it through the five lifecycle hooks. See crate-level docs for ordering.
§Associated constants
NAME— an optional static identifier surfaced viaServiceHandle::nameand used in tracing spans. Set toSome("validator")etc.
Provided Associated Constants§
Required Methods§
Sourcefn pre_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StartContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn pre_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StartContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called before peer / RPC servers bind. Typical work: open stores, replay journal, restore state.
Sourcefn on_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StartContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_start<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StartContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called after peer / RPC servers bind but before run begins. Typical
work: announce capabilities, warm caches.
Sourcefn run<'life0, 'async_trait>(
&'life0 self,
ctx: RunContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn run<'life0, 'async_trait>(
&'life0 self,
ctx: RunContext,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Main run loop. Returns on:
ctx.shutdown.cancelled()firing (graceful), OR- a fatal internal error (
Err).
Sourcefn on_stop<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StopContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_stop<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StopContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called after run returns. Typical work: flush stores,
write snapshots. Errors here are reported but do not stop post_stop
from also running.
Sourcefn post_stop<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StopContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn post_stop<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 StopContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Final hook. Typical work: close stores, release file locks.
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.