DefaultMessageBroker

Struct DefaultMessageBroker 

Source
pub struct DefaultMessageBroker { /* private fields */ }

Implementations§

Source§

impl DefaultMessageBroker

Source

pub fn new() -> Self

Examples found in repository?
examples/simple.rs (line 117)
116fn main() {
117    let tb: Arc<dyn MessageBroker> = Arc::new(DefaultMessageBroker::new());
118
119    let mut s0 = TestSubsciber0::new();
120    s0.subscribe(Arc::clone(&tb));
121
122    let mut s1 = TestSubsciber1::new();
123    s1.subscribe(Arc::clone(&tb));
124
125    let p0 = TestPublisher::new(Arc::clone(&tb));
126    let p1 = TestPublisher::new(Arc::clone(&tb));
127
128    p0.publish(Arc::new(TestMsg0(2)));
129    s1.deactivate();
130    p1.publish(Arc::new(TestMsg0(5)));
131    s1.activate();
132    p1.publish(Arc::new(TestMsg1(3)));
133    p1.publish(Arc::new(TestMsg1(6)));
134
135    s0.process_messages();
136    s1.process_messages();
137}

Trait Implementations§

Source§

impl MessageBroker for DefaultMessageBroker

Source§

fn get_message_topic(&self, msg_type_id: MessageTypeId) -> Arc<MessageTopic>

Gets MessageTopic which is responsible for handling messages of the given type.
Source§

fn register_subscription( self: Arc<Self>, sub: &mut dyn ErasedSubscription, ) -> Result<(), MessageBrokerError>

Registers the subscription in the broker. Read more
Source§

fn unregister_subscription( &self, sub: &mut dyn ErasedSubscription, ) -> Result<(), MessageBrokerError>

Unregisters the subscription in the broker. Read more
Source§

fn publish_message( &self, msg: Arc<dyn Message>, ) -> Result<(), MessageBrokerError>

Sends the given message to all subscribers which are listening for messages of its type.

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.