Struct CompositeContext

Source
pub struct CompositeContext<R: ResourceLoaderComponent, O: OffloaderComponent, M: MailIdGenComponent> { /* private fields */ }
Expand description

The CompositeContext is the simplest way to get an Context implementation.

Any custom Context implementations should be realized through the CompositeContext if possible.

This type consists of 3 components it forward all method calls from Context to. This allows the library to have a single Context type but match and mix the parts about resource loading, offloading and id generation in whichever way it fits best.

The composite context will store the components inside of an Arc so that it can be easily shared through an application, it also means non of the components have to implement Clone.

Implementations§

Source§

impl<R, O, M> CompositeContext<R, O, M>

Source

pub fn new(resource_loader: R, offloader: O, message_id_gen: M) -> Self

Create a new context from the given components.

Source

pub fn resource_loader(&self) -> &R

Returns a reference to the resource loader component.

Source

pub fn offloader(&self) -> &O

Returns a reference to the offloader component.

Source

pub fn id_gen(&self) -> &M

Returns a reference to the id generation component.

Trait Implementations§

Source§

impl<R, O, M> Clone for CompositeContext<R, O, M>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R, O, M> Context for CompositeContext<R, O, M>

Source§

fn load_resource( &self, source: &Source, ) -> SendBoxFuture<MaybeEncData, ResourceLoadingError>

Loads and transfer encodes a Data instance. Read more
Source§

fn load_transfer_encoded_resource( &self, resource: &Resource, ) -> SendBoxFuture<EncData, ResourceLoadingError>

Loads and Transfer encodes a Resource instance. Read more
Source§

fn offload<F>(&self, fut: F) -> SendBoxFuture<F::Item, F::Error>
where F: Future + Send + 'static, F::Item: Send + 'static, F::Error: Send + 'static,

offloads the execution of the future fut to somewhere else e.g. a cpu pool
Source§

fn generate_content_id(&self) -> ContentId

generate a unique content id Read more
Source§

fn generate_message_id(&self) -> MessageId

generate a unique content id Read more
Source§

fn offload_fn<FN, I>(&self, func: FN) -> SendBoxFuture<I::Item, I::Error>
where FN: FnOnce() -> I + Send + 'static, I: IntoFuture + 'static, I::Future: Send + 'static, I::Item: Send + 'static, I::Error: Send + 'static,

offloads the execution of the function func to somewhere else e.g. a cpu pool
Source§

impl<R: Debug + ResourceLoaderComponent, O: Debug + OffloaderComponent, M: Debug + MailIdGenComponent> Debug for CompositeContext<R, O, M>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<R, O, M> Freeze for CompositeContext<R, O, M>

§

impl<R, O, M> RefUnwindSafe for CompositeContext<R, O, M>

§

impl<R, O, M> Send for CompositeContext<R, O, M>

§

impl<R, O, M> Sync for CompositeContext<R, O, M>

§

impl<R, O, M> Unpin for CompositeContext<R, O, M>

§

impl<R, O, M> UnwindSafe for CompositeContext<R, O, M>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HeaderTryFrom<T> for T

Source§

impl<F, T> HeaderTryInto<T> for F
where T: HeaderTryFrom<F>,

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<C> MailIdGenComponent for C
where C: Context,

Source§

fn generate_message_id(&self) -> MessageId

Calls to Context::generate_message_id will be forwarded to this method.
Source§

fn generate_content_id(&self) -> MessageId

Calls to Context::generate_content_id will be forwarded to this method.
Source§

impl<C> OffloaderComponent for C
where C: Context,

Source§

fn offload<F>( &self, fut: F, ) -> Box<dyn Future<Item = <F as Future>::Item, Error = <F as Future>::Error> + Send>
where F: Future + Send + 'static, <F as Future>::Item: Send + 'static, <F as Future>::Error: Send + 'static,

Calls to Context::offload and Context::offload_fn will be forwarded to this method.
Source§

impl<C> ResourceLoaderComponent for C
where C: Context,

Source§

fn load_resource( &self, source: &Source, _: &impl Context, ) -> Box<dyn Future<Item = MaybeEncData, Error = ResourceLoadingError> + Send>

Calls to Context::load_resource will be forwarded to this method. Read more
Source§

fn load_transfer_encoded_resource( &self, resource: &Resource, _: &impl Context, ) -> Box<dyn Future<Item = EncData, Error = ResourceLoadingError> + Send>

Calls to Context::transfer_encode_resource will be forwarded to this method. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.