Crate companion_service[][src]

Expand description

Run services along with your executable. This is useful, for example, to run and stop databases and message brokers automatically with cargo test.

Automatic startup and shutdown of services relies on the ctor crate. Service registration is done with the linkme crate and the SERVICES static. And each service is defined by an object that implements the Service trait:

use linkme::distributed_slice;
use companion_service::{Service, SERVICES};

struct Dummy;

impl Service for Dummy {
  fn name(&self) -> &str {
    "dummy"
  }

  fn start(&self) {
    print!("start!");
  }

  fn stop(&self) {
    print!("stop!");
  }
}

#[distributed_slice(SERVICES)]
static DUMMY: &(dyn Service + Sync) = &Dummy;

Statics

The distributed slice handled by linkme.

Traits

Trait for all services handled by this crate.

Functions

Restarts all services with the given name.

Starts all services with the given name.

Stops all services with the given name.