Skip to main content

Service

Struct Service 

Source
pub struct Service<N, A, R>
where N: NodeLifecycle, A: PeerApi, R: RpcApi,
{ /* private fields */ }
Expand description

The top-level orchestration handle.

See the crate-level documentation for architecture + lifecycle diagram. Service owns the business-logic node and the peer / RPC API adapters; driving start() runs the full lifecycle.

§Type parameters

  • N — the NodeLifecycle implementation (the business core).
  • A — the PeerApi implementation. Use () for binaries that don’t serve a peer surface (daemon, wallet).
  • R — the RpcApi implementation. Use () for binaries that don’t serve RPC (introducer, relay).

Implementations§

Source§

impl<N, A, R> Service<N, A, R>
where N: NodeLifecycle, A: PeerApi, R: RpcApi,

Source

pub fn new(node: N, peer_api: A, rpc_api: R) -> Self

Construct a new service from its three components.

No runtime work happens here — ports are not bound, stores are not opened. All of that runs inside start().

Source

pub fn handle(&self) -> ServiceHandle

Return a cloneable handle for out-of-process-lifetime commands (signal handlers, RPC admin methods).

The returned handle remains valid after Service is dropped — its operations simply become no-ops.

Source

pub fn node(&self) -> &Arc<N>

Borrow the node. Mostly useful in tests; production callers should share state via the Arc<N> they constructed before Service::new.

Source

pub fn peer_api(&self) -> &Arc<A>

Borrow the peer API.

Source

pub fn rpc_api(&self) -> &Arc<R>

Borrow the RPC API.

Source

pub fn shutdown_token(&self) -> &ShutdownToken

Borrow the shutdown token. Use this to give background tasks a way to notice shutdown has been requested.

Source

pub fn tasks(&self) -> &TaskRegistry

Borrow the task registry.

Source

pub fn request_shutdown(&self, reason: ShutdownReason)

Request a graceful shutdown. Idempotent — only the first reason is recorded.

Source

pub async fn start(self) -> Result<ExitStatus>

Drive the full lifecycle: pre_start → on_start → run → on_stop → post_stop. Returns once run exits (graceful or error) OR a shutdown has been requested.

§Error handling
  • A failure in pre_start short-circuits without calling any later hook.
  • A failure in on_start calls post_stop but skips run and on_stop.
  • A failure in run still calls on_stop + post_stop.
  • A failure in on_stop is recorded but does not block post_stop.
  • Panics inside run are caught via scopeguard-style drop logic and reported as ExitReason::RunError.

Calling start twice on the same Service returns ServiceError::AlreadyRunning.

Auto Trait Implementations§

§

impl<N, A, R> Freeze for Service<N, A, R>

§

impl<N, A, R> !RefUnwindSafe for Service<N, A, R>

§

impl<N, A, R> Send for Service<N, A, R>

§

impl<N, A, R> Sync for Service<N, A, R>

§

impl<N, A, R> Unpin for Service<N, A, R>

§

impl<N, A, R> UnsafeUnpin for Service<N, A, R>

§

impl<N, A, R> !UnwindSafe for Service<N, A, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more