DataSource

Trait DataSource 

Source
pub trait DataSource: Send + Debug {
    // Required methods
    fn poll(&mut self) -> Option<Snapshot>;
    fn description(&self) -> &str;
    fn error(&self) -> Option<&str>;
}
Expand description

Trait for receiving monitor data from various sources.

Implementations of this trait provide monitor snapshots from different backends - file polling, message bus subscriptions, or in-memory channels.

§Example

use buswatch_tui::{FileSource, DataSource};

let mut source = FileSource::new("monitor.json");
if let Some(snapshot) = source.poll() {
    println!("Got {} modules", snapshot.len());
}

Required Methods§

Source

fn poll(&mut self) -> Option<Snapshot>

Poll for the latest snapshot.

Returns Some(snapshot) if new data is available, None otherwise. This method should be non-blocking.

Source

fn description(&self) -> &str

Returns a human-readable description of the source.

Used for display in the TUI status bar.

Source

fn error(&self) -> Option<&str>

Check if the source has encountered an error.

Returns the error message if an error occurred during the last poll.

Implementors§