FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    MessageBus

    struct · ferroui-reactiveui · v0.5.0

    struct MessageBus
    

    A message bus: a simple way for view models and other objects to talk to each other without knowing each other (MessageBus).

    Which messages go where is decided by the type of the message and a contract, a string that tells apart the messages of the same type and that the client chooses. The typed operations are the methods of IMessageBusExt:

    use ferroui_reactive::ObservableExt;
    use ferroui_reactiveui::{IMessageBusExt, MessageBus};
    use std::cell::RefCell;
    use std::rc::Rc;
    
    let bus = MessageBus::new();
    let received = Rc::new(RefCell::new(Vec::new()));
    let log = received.clone();
    let _subscription = bus.listen::<String>().subscribe_next(move |message| log.borrow_mut().push(message));
    
    bus.send_message("Hello".to_owned());
    bus.send_message_with_contract("Elsewhere".to_owned(), Some("other"));
    assert_eq!(*received.borrow(), ["Hello"]);
    

    A channel delivers on the scheduler registered for it, the current-thread scheduler by default. A channel holds the latest message, which listen_include_latest replays (the default value of the type before any message).

    View source

    Members

    new

    fn new() -> Rc<Self>
    

    A bus without channels.

    Source

    current

    fn current() -> Rc<dyn IMessageBus>
    

    The bus of the application (Current): a MessageBus unless another one was set.

    Source

    set_current

    fn set_current(bus: Rc<dyn IMessageBus>)
    

    Replaces the bus of the application (Current { set; }), for tests or another implementation.

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • Borrow<T>
    • BorrowMut<T>
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • Debug
    • IEnableLogger
    • IMessageBus

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.