[−][src]Trait spirit::fragment::Transformation
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
InputResource
is the resource on the transformation input; this one will be changed every time the transformation is called.InputInstaller
is the original installer that was present in the pipeline before the transformation got added. Note that not all installers at that point are able to install theInputResource
. But if it is able, it can be used to delegate from theOutputInstaller
(or just use it vanilla).SubFragment
is the fragments theTransformation
will be used on. EachResource
is always accompanied by theFragment
it came from. Note that this might be some sub-part of the originalFragment
, as theDriver
is allowed to cut it into smaller pieces.
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
.
Required methods
fn installer(
&mut self,
installer: InputInstaller,
name: &'static str
) -> Self::OutputInstaller
&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>
&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.
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]
A: Transformation<R, I, S>,
B: Transformation<A::OutputResource, A::OutputInstaller, S>,
type OutputResource = B::OutputResource
type OutputInstaller = B::OutputInstaller
fn installer(&mut self, installer: I, name: &'static str) -> B::OutputInstaller
[src]
fn transform(
&mut self,
resource: R,
fragment: &S,
name: &'static str
) -> Result<Self::OutputResource, AnyError>
[src]
&mut self,
resource: R,
fragment: &S,
name: &'static str
) -> Result<Self::OutputResource, AnyError>
impl<R: 'static, I, S> Transformation<R, I, S> for NopTransformation
[src]
type OutputResource = R
type OutputInstaller = I
fn installer(&mut self, installer: I, _: &str) -> I
[src]
fn transform(
&mut self,
resource: R,
_: &S,
_: &str
) -> Result<Self::OutputResource, AnyError>
[src]
&mut self,
resource: R,
_: &S,
_: &str
) -> Result<Self::OutputResource, AnyError>
impl<T, I, R, OI, S> Transformation<R, OI, S> for SetInstaller<T, I> where
T: Transformation<R, OI, S>,
[src]
T: Transformation<R, OI, S>,
type OutputResource = T::OutputResource
type OutputInstaller = I
fn installer(&mut self, _installer: OI, _: &'static str) -> I
[src]
fn transform(
&mut self,
resource: R,
fragment: &S,
name: &'static str
) -> Result<Self::OutputResource, AnyError>
[src]
&mut self,
resource: R,
fragment: &S,
name: &'static str
) -> Result<Self::OutputResource, AnyError>
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]
T: Transformation<Rin, I, S>,
M: FnMut(T::OutputResource) -> Rout,
Rout: 'static,
type OutputResource = Rout
type OutputInstaller = T::OutputInstaller
fn installer(&mut self, installer: I, name: &'static str) -> T::OutputInstaller
[src]
fn transform(
&mut self,
resource: Rin,
fragment: &S,
name: &'static str
) -> Result<Rout, AnyError>
[src]
&mut self,
resource: Rin,
fragment: &S,
name: &'static str
) -> Result<Rout, AnyError>