Skip to main content

Module composition

Module composition 

Source
Expand description

Combinators that build one pipeline component out of several.

  • ComposedVehicle joins an independent StateSource and Actuator into a Vehicle, e.g. an IMU/estimator and an ESC driver on hardware. The two halves don’t see each other, so it doesn’t fit a state source that needs the actuator’s data (such as a simulator bridge’s truth state); that case needs a different combinator.
  • (A, B) is a TelemetryPublisher that fans each record out to both sinks; nest tuples for more. () is the no-op sink.

Both are allocation-free and add no dynamic dispatch.

use stable_flight::{TelemetryPublisher, TelemetryRecord};

#[derive(Default)]
struct Counter(u32);
impl TelemetryPublisher for Counter {
    fn publish(&mut self, _record: &TelemetryRecord) {
        self.0 += 1;
    }
}

// A ground-station sink, a log sink, and `()` where a slot needs no sink.
let mut sinks = (Counter::default(), (Counter::default(), ()));
sinks.publish(&record);
assert_eq!((sinks.0.0, sinks.1.0.0), (1, 1));

Structs§

ComposedVehicle
A Vehicle made of a separate state source and actuator.