#service #constructor #test #destructor

companion-service

Run services along with your executable

1 unstable release

0.1.0 Aug 1, 2021

#9 in #destructor

BSD-3-Clause

5KB

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;

Dependencies

~1.5MB
~38K SLoC