[][src]Trait spirit::fragment::Transformation

pub trait Transformation<InputResource, InputInstaller, SubFragment> {
    type OutputResource: 'static;
    type OutputInstaller;
    fn installer(
        &mut self,
        installer: InputInstaller,
        name: &'static str
    ) -> Self::OutputInstaller;
fn transform(
        &mut self,
        resource: InputResource,
        fragment: &SubFragment,
        name: &'static str
    ) -> Result<Self::OutputResource, AnyError>; }

A transformation of resources.

A Pipeline can contain a transformation of the Resource produced by the Fragment. This trait describes a transformation.

Note that transformations in a pipeline are usually composed together.

The transformation is also allowed (and sometimes required) to either transform or replace the Installer of the Pipeline. The old Installer might not be able to install the new Resource (since the type can change during the transformation) or might not even exist.

A transformation can be quite arbitrary thing that simply takes the old resource and produces something new. But more often that not, it is used to somehow make a „dead“ resource (eg. a network socket) „alive“ (eg. wrap it into a future that is then installed) ‒ or, in other words, to tie the resource to some functionality.

It is also possible to use a transformation to post-process and tweak the resource a bit (add more loggers, change a bit of configuration of the resource, ...).

Type parameters

Associated Types

type OutputResource: 'static

The type of resource after the transformation.

type OutputInstaller

The type of installer after the transformation.

This can be something completely new, or something that somehow delegates or uses the InputResource.

Loading content...

Required methods

fn installer(
    &mut self,
    installer: InputInstaller,
    name: &'static str
) -> Self::OutputInstaller

Creates the installer.

This is called by the pipeline exactly once, with the original installer, to produce the transformed installer.

Note that some transformations are composed from multiple transformations and they are not mandated to call this method. Nevertheless, it is violation of contract to call this more than once.

fn transform(
    &mut self,
    resource: InputResource,
    fragment: &SubFragment,
    name: &'static str
) -> Result<Self::OutputResource, AnyError>

Transforms one instance of the resource.

The fragment parameter was the fragment that was used to create the resource. Note that there might have been some other transformations between the creation and this transformation and therefore the resource produced by the fragment might be something else than what is being put into the transformation.

Nevertheless, the transformation is allowed to look into the fragment ‒ for example to examine additional configuration not used to directly create the resource, but maybe configure the „alive“ part that this transformation adds.

Loading content...

Implementors

impl<A, B, R, I, S> Transformation<R, I, S> for ChainedTransformation<A, B> where
    A: Transformation<R, I, S>,
    B: Transformation<A::OutputResource, A::OutputInstaller, S>, 
[src]

type OutputResource = B::OutputResource

type OutputInstaller = B::OutputInstaller

impl<R: 'static, I, S> Transformation<R, I, S> for NopTransformation[src]

type OutputResource = R

type OutputInstaller = I

impl<T, I, R, OI, S> Transformation<R, OI, S> for SetInstaller<T, I> where
    T: Transformation<R, OI, S>, 
[src]

type OutputResource = T::OutputResource

type OutputInstaller = I

impl<T, M, Rin, Rout, I, S> Transformation<Rin, I, S> for AndThen<T, M> where
    T: Transformation<Rin, I, S>,
    M: FnMut(T::OutputResource) -> Result<Rout, AnyError>,
    Rout: 'static, 
[src]

type OutputResource = Rout

type OutputInstaller = T::OutputInstaller

impl<T, M, Rin, Rout, I, S> Transformation<Rin, I, S> for Map<T, M> where
    T: Transformation<Rin, I, S>,
    M: FnMut(T::OutputResource) -> Rout,
    Rout: 'static, 
[src]

type OutputResource = Rout

type OutputInstaller = T::OutputInstaller

Loading content...