pub struct BasicBuilder<Ev>where
Ev: Debug,{ /* private fields */ }Expand description
The BasicBuilder helps you to create a BasicMediator.
The BasicBuilder is part of the builder pattern.
It has only two functionalities. The first one is adding a Listener via
BasicBuilder::add_listener().
The second one is the mandatory BuilderFlow::build(), which returns
a BasicMediator.
Implementations§
Source§impl<Ev> BasicBuilder<Ev>where
Ev: Debug,
impl<Ev> BasicBuilder<Ev>where
Ev: Debug,
Sourcepub fn add_listener<F>(self, f: F) -> Selfwhere
F: Listener<Ev>,
pub fn add_listener<F>(self, f: F) -> Selfwhere
F: Listener<Ev>,
Adds a user-defined listener to the BasicBuilder.
The supplied type must be a Listener.
As such, it must implement Send and Fn(Ev),
besides being 'static.
As a side note, here, Ev is the user-defined event type
that must be Clone and Debug.
§Examples
Basic usage:
use mediator_sys::synchronous::basic::*;
#[derive(Debug, Clone)]
enum MyEvent {
One,
Two
}
let mediator = BasicMediator::<MyEvent>::builder()
.add_listener(|ev| {
/* Your listening logic */
})
.build();Trait Implementations§
Source§impl<M, Ev> BasicMediatorBuilderInterface<M, Ev> for BasicBuilder<Ev>where
Ev: Debug,
impl<M, Ev> BasicMediatorBuilderInterface<M, Ev> for BasicBuilder<Ev>where
Ev: Debug,
Source§fn add_listener<F>(self, f: F) -> Selfwhere
F: Listener<Ev>,
fn add_listener<F>(self, f: F) -> Selfwhere
F: Listener<Ev>,
Adds a user-defined listener to the BasicBuilder.
To be able to supply a closure that implements Listener,
it must satisfy Send and 'static bounds.
Also it must be a Fn(Ev) with a return type of ()
where Ev is the user-defined event type
that must be Clone and Debug.
Source§impl<Ev> BuilderFlow<BasicMediator<Ev>> for BasicBuilder<Ev>where
Ev: Debug,
impl<Ev> BuilderFlow<BasicMediator<Ev>> for BasicBuilder<Ev>where
Ev: Debug,
Source§fn build(self) -> BasicMediator<Ev>
fn build(self) -> BasicMediator<Ev>
Builds the BasicMediator and returns it.
Because BasicMediator implements BuilderInternal,
which in turn means, that the BasicBuilder implements BuilderFlow
and not crate::builder::TryBuilderFlow, this method will
always return a BasicMediator as stated by the return type.
Source§impl<Ev> BuilderInternal<BasicMediator<Ev>, BasicBuilder<Ev>> for BasicMediator<Ev>where
Ev: Debug,
impl<Ev> BuilderInternal<BasicMediator<Ev>, BasicBuilder<Ev>> for BasicMediator<Ev>where
Ev: Debug,
Source§fn builder() -> BasicBuilder<Ev>
fn builder() -> BasicBuilder<Ev>
Creates a BasicBuilder with the goal of producing a BasicMediator.