pub struct MessageBus { /* private fields */ }Expand description
An inter-agent message bus supporting publish/subscribe and history.
Implementations§
Source§impl MessageBus
impl MessageBus
pub fn new() -> Self
Sourcepub async fn send(&self, msg: AgentMessage)
pub async fn send(&self, msg: AgentMessage)
Send a message. Stores in history with bounded eviction and notifies relevant subscribers.
Sourcepub fn with_capacity(cap: usize) -> Self
pub fn with_capacity(cap: usize) -> Self
Create a MessageBus with a custom capacity (for testing).
Sourcepub async fn subscribe(&self, role: &str) -> Receiver<AgentMessage>
pub async fn subscribe(&self, role: &str) -> Receiver<AgentMessage>
Subscribe to messages for a given role. Returns a broadcast receiver.
Sourcepub async fn inbox(&self, role: &str) -> Vec<AgentMessage>
pub async fn inbox(&self, role: &str) -> Vec<AgentMessage>
Get all messages addressed to this role (including broadcasts).
Sourcepub async fn outbox(&self, role: &str) -> Vec<AgentMessage>
pub async fn outbox(&self, role: &str) -> Vec<AgentMessage>
Get all messages sent by this role.
Sourcepub async fn history(&self) -> VecDeque<AgentMessage>
pub async fn history(&self) -> VecDeque<AgentMessage>
Get the full message history (bounded to MESSAGE_BUS_CAPACITY).
Trait Implementations§
Source§impl Clone for MessageBus
impl Clone for MessageBus
Auto Trait Implementations§
impl !RefUnwindSafe for MessageBus
impl !UnwindSafe for MessageBus
impl Freeze for MessageBus
impl Send for MessageBus
impl Sync for MessageBus
impl Unpin for MessageBus
impl UnsafeUnpin for MessageBus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoMaybeUndefined<T> for T
impl<T> IntoMaybeUndefined<T> for T
Source§fn into_maybe_undefined(self) -> MaybeUndefined<T>
fn into_maybe_undefined(self) -> MaybeUndefined<T>
Converts this value into a three-state builder argument.
Source§impl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
Source§fn into_option(self) -> Option<T>
fn into_option(self) -> Option<T>
Converts this value into an optional builder argument.