RateConfig

Trait RateConfig 

Source
pub trait RateConfig {
    // Required method
    fn rate_hz(&self) -> f32;

    // Provided methods
    fn create_interval(&self) -> Interval { ... }
    fn period(&self) -> Duration { ... }
}
Expand description

Trait for node configurations that specify an update rate

This trait provides a standard interface for nodes that publish at a fixed rate. Implement this trait on your node’s config struct to enable convenient rate-based interval creation.

§Example

use mecha10::prelude::*;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CameraConfig {
    pub fps: f32,
    pub width: u32,
    pub height: u32,
}

impl RateConfig for CameraConfig {
    fn rate_hz(&self) -> f32 {
        self.fps
    }
}

// Now you can use the config to create intervals easily:
let mut interval = config.create_interval();
loop {
    interval.tick().await;
    // Publish at configured rate
}

Required Methods§

Source

fn rate_hz(&self) -> f32

Get the update rate in Hertz (cycles per second)

Provided Methods§

Source

fn create_interval(&self) -> Interval

Create a tokio interval from the configured rate

This is a convenience method that converts the rate to a Duration and creates a tokio::time::Interval.

Source

fn period(&self) -> Duration

Get the period (time between updates) as a Duration

Implementors§