Skip to main content

AlertBus

Struct AlertBus 

Source
pub struct AlertBus { /* private fields */ }
Expand description

Central alert bus.

Components fire alerts via AlertBus::fire; subscribers receive them synchronously in the same call.

§Example

use obs_core::bus::AlertBus;
let bus = AlertBus::new();
assert_eq!(bus.subscriber_count(), 0);

Implementations§

Source§

impl AlertBus

Source

pub fn new() -> Self

Create a new bus with the default history limit (1 000 entries).

Source

pub fn with_history_limit(limit: usize) -> Self

Source

pub fn subscribe( &mut self, handler: Box<dyn AlertHandler>, min_severity: AlertSeverity, source: Option<String>, )

Register a handler that receives all alerts at or above min_severity. If source is Some, only alerts from that source component are delivered.

Source

pub fn fire(&mut self, alert: Alert)

Dispatch alert to all matching subscribers and add it to history.

Source

pub fn history(&self) -> &[Alert]

All alerts in history (oldest first).

Source

pub fn history_at_or_above( &self, min: AlertSeverity, ) -> impl Iterator<Item = &Alert>

History filtered to severity >= min.

Source

pub fn history_for_source<'a>( &'a self, source: &str, ) -> impl Iterator<Item = &'a Alert>

History filtered to a single source.

Source

pub fn subscriber_count(&self) -> usize

Trait Implementations§

Source§

impl Default for AlertBus

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.