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

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();

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

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.

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().

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.

Creates a CxAwareAsyncBuilder with the goal of producing a CxAwareAsyncMediator.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.