Crate boomerang

Source
Expand description

§Boomerang 🪃

crates.io MIT/Apache 2.0 Downloads CI docs codecov

A deterministic middleware framework for robotics and distributed systems.

§License

Licensed under either of

  • Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

§Example

Build and run a Reactor with reactions that respond to startup and shutdown actions:

use boomerang::{builder::prelude::*, runtime, Reactor, Reaction};

struct State {
    success: bool,
}

#[derive(Reactor)]
#[reactor(
    state = "State",
    reaction = "ReactionStartup",
    reaction = "ReactionShutdown"
)]
struct HelloWorld;

#[derive(Reaction)]
#[reaction(
    reactor = "HelloWorld",
    triggers(startup)
)]
struct ReactionStartup;

impl Trigger<HelloWorld> for ReactionStartup {
    fn trigger(self, _ctx: &mut runtime::Context, state: &mut State) {
        println!("Hello World.");
        state.success = true;
    }
}

#[derive(Reaction)]
#[reaction(
    reactor = "HelloWorld",
    triggers(shutdown)
)]
struct ReactionShutdown;

impl Trigger<HelloWorld> for ReactionShutdown {
    fn trigger(self, _ctx: &mut runtime::Context, state: &mut State) {
        println!("Shutdown invoked.");
        assert!(state.success, "ERROR: startup reaction not executed.");
    }
}

let mut env_builder = EnvBuilder::new();
let reactor = HelloWorld::build(
    "hello_world",
    State {
        success: false
    },
    None,
    None,
    &mut env_builder
).unwrap();
let (mut env, triggers, _) = env_builder.into_runtime_parts().unwrap();
let mut sched = runtime::Scheduler::new(env, triggers, true, false);
sched.event_loop();

§Feature flags

  • derive (enabled by default) — Procedural macro support for generating code from reactor models
  • serde — Support for serialization
  • parallel — Support for parallel execution
  • graphviz — Support generating graphviz diagrams from reactor models

Re-exports§

pub use boomerang_builder as builder;
pub use boomerang_runtime as runtime;

Modules§

flatten_transposed
Flatten Transposed Iterator

Enums§

BoomerangError
Top-level error type for Boomerang