CxAwareAsyncBuilder

Struct CxAwareAsyncBuilder 

Source
pub struct CxAwareAsyncBuilder<Dep, Ev>
where Dep: Debug, Ev: Debug,
{ /* private fields */ }
Available on crate feature 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>
where Dep: Debug, Ev: Debug,

Source

pub fn add_listener<F>(self, f: F) -> Self
where 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();
Source

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>
where Dep: Debug, Ev: Debug,

Source§

fn add_listener<F>(self, f: F) -> Self
where 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>
where Dep: Debug, Ev: Debug,

Source§

fn add_dependency(self, dep: Dep) -> Self
where 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>
where Dep: Debug, Ev: Debug,

Source§

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.

Source§

type Error = NoCxAvailable

Source§

impl<Dep, Ev> TryBuilderInternal<CxAwareAsyncMediator<Dep, Ev>, CxAwareAsyncBuilder<Dep, Ev>> for CxAwareAsyncMediator<Dep, Ev>
where Dep: Debug, Ev: Debug,

Source§

fn builder() -> CxAwareAsyncBuilder<Dep, Ev>

Creates a CxAwareAsyncBuilder with the goal of producing a CxAwareAsyncMediator.

Auto Trait Implementations§

§

impl<Dep, Ev> Freeze for CxAwareAsyncBuilder<Dep, Ev>
where Dep: Freeze,

§

impl<Dep, Ev> !RefUnwindSafe for CxAwareAsyncBuilder<Dep, Ev>

§

impl<Dep, Ev> Send for CxAwareAsyncBuilder<Dep, Ev>
where Dep: Send, Ev: Send,

§

impl<Dep, Ev> !Sync for CxAwareAsyncBuilder<Dep, Ev>

§

impl<Dep, Ev> Unpin for CxAwareAsyncBuilder<Dep, Ev>
where Dep: Unpin,

§

impl<Dep, Ev> !UnwindSafe for CxAwareAsyncBuilder<Dep, Ev>

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.