pub struct CxAwareAsyncBuilder<Dep, Ev>{ /* private fields */ }async only.Expand description
The CxAwareAsyncBuilder helps you to create a CxAwareAsyncMediator.
The CxAwareAsyncBuilder is part of the builder pattern.
It has three functionalities. The first one is adding a Listener via
CxAwareAsyncBuilder::add_listener().
Secondly, a dependency Dep can be added via CxAwareAsyncBuilder::add_dependency().
This must be done in order to receive a CxAwareAsyncMediator from TryBuilderFlow::build().
The third functionality is the mandatory TryBuilderFlow::build(), which returns
a Result of type [Result<CxAwareAsyncMediator<Dep, Ev>, Self::Error>].
Implementations§
Source§impl<Dep, Ev> CxAwareAsyncBuilder<Dep, Ev>
impl<Dep, Ev> CxAwareAsyncBuilder<Dep, Ev>
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 CxAwareAsyncBuilder.
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.
Note: The following example will add a Listener to the builder,
but the result of .build() here will be an Err value.
This is because in order to receive a valid CxAwareAsyncMediator
you need to add a dependency. See CxAwareAsyncBuilder::add_dependency().
§Examples
Basic usage:
use mediator_sys::asynchronous::contextaware::*;
use std::sync::Arc;
#[derive(Debug, Clone)]
enum MyEvent {
One,
Two
}
#[derive(Debug, Default)]
struct MyContext(Arc<u32>);
let mediator = CxAwareAsyncMediator::<MyContext, MyEvent>::builder()
.add_listener(|ev| {
/* Your listening logic */
})
.build();Sourcepub fn add_dependency(self, dep: Dep) -> Self
pub fn add_dependency(self, dep: Dep) -> Self
Adds a user-defined dependency of type Dep to the CxAwareAsyncBuilder.
The dependency will act as a context and become available in super::CxAwareAsyncRequestHandler::handle().
§Examples
Basic usage:
use mediator_sys::asynchronous::contextaware::*;
use std::sync::Arc;
#[derive(Debug, Clone)]
enum MyEvent {
One,
Two
}
#[derive(Debug, Default)]
struct MyContext(Arc<u32>);
let mediator = CxAwareAsyncMediator::<MyContext, MyEvent>::builder()
.add_dependency(MyContext::default())
.build();Trait Implementations§
Source§impl<M, Dep, Ev> BasicMediatorBuilderInterface<M, Ev> for CxAwareAsyncBuilder<Dep, Ev>
impl<M, Dep, Ev> BasicMediatorBuilderInterface<M, Ev> for CxAwareAsyncBuilder<Dep, Ev>
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 CxAwareAsyncBuilder.
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<M, Dep, Ev> CxAwareMediatorBuilderInterface<M, Dep, Ev> for CxAwareAsyncBuilder<Dep, Ev>
impl<M, Dep, Ev> CxAwareMediatorBuilderInterface<M, Dep, Ev> for CxAwareAsyncBuilder<Dep, Ev>
Source§fn add_dependency(self, dep: Dep) -> Selfwhere
Ev: Debug,
fn add_dependency(self, dep: Dep) -> Selfwhere
Ev: Debug,
Adds a user-defined dependency of type Dep to the CxAwareAsyncBuilder.
The dependency will act as a context and become available in super::CxAwareAsyncRequestHandler::handle().
Source§impl<Dep, Ev> TryBuilderFlow<CxAwareAsyncMediator<Dep, Ev>> for CxAwareAsyncBuilder<Dep, Ev>
impl<Dep, Ev> TryBuilderFlow<CxAwareAsyncMediator<Dep, Ev>> for CxAwareAsyncBuilder<Dep, Ev>
Source§fn build(self) -> Result<CxAwareAsyncMediator<Dep, Ev>, Self::Error>
fn build(self) -> Result<CxAwareAsyncMediator<Dep, Ev>, Self::Error>
Builds the CxAwareAsyncMediator and returns it.
Because CxAwareAsyncMediator implements TryBuilderInternal,
which in turn means, that the CxAwareAsyncBuilder implements TryBuilderFlow
this method will return a [Result<CxAwareAsyncMediator<Dep, Ev>, Self::Error>] as stated by the return type.
Note that here Self::Error is of type NoCxAvailable, which means that no dependecy was added in
the process of building.
type Error = NoCxAvailable
Source§impl<Dep, Ev> TryBuilderInternal<CxAwareAsyncMediator<Dep, Ev>, CxAwareAsyncBuilder<Dep, Ev>> for CxAwareAsyncMediator<Dep, Ev>
impl<Dep, Ev> TryBuilderInternal<CxAwareAsyncMediator<Dep, Ev>, CxAwareAsyncBuilder<Dep, Ev>> for CxAwareAsyncMediator<Dep, Ev>
Source§fn builder() -> CxAwareAsyncBuilder<Dep, Ev>
fn builder() -> CxAwareAsyncBuilder<Dep, Ev>
Creates a CxAwareAsyncBuilder with the goal of producing a CxAwareAsyncMediator.