pub struct Transform<I, O> { /* private fields */ }Expand description
A composable transformation pipeline
Transform<I, O> represents a transformation from type I to type O.
It can be composed with other transforms using the add method.
§Type Safety
The type system ensures that transforms can only be composed if their input/output types are compatible. For example:
let t1: Transform<String, TokenStream> = ...;
let t2: Transform<Document, String> = ...;
// This will fail to compile - TokenStream != Document
let bad = t1.add_transform(&t2);Implementations§
Source§impl<I, O> Transform<I, O>
impl<I, O> Transform<I, O>
Sourcepub fn identity() -> Self
pub fn identity() -> Self
Create a new identity transform that passes input through unchanged
Note: This only works when I = O
Sourcepub fn then<O2, S>(self, stage: S) -> Transform<I, O2>
pub fn then<O2, S>(self, stage: S) -> Transform<I, O2>
Add a stage to this transform, returning a new transform with extended output type
This is the core composition method. It chains this transform’s output into
the next stage’s input, creating a new transform from I to O2.
§Type Safety
The compiler ensures that the stage’s input type matches this transform’s output type.
§Example
let t1: Transform<String, Tokens> = ...;
let t2: Transform<Tokens, Ast> = ...;
let combined: Transform<String, Ast> = t1.then_transform(&t2);Sourcepub fn then_transform<O2>(
self,
next: &'static Transform<O, O2>,
) -> Transform<I, O2>where
I: 'static,
O: 'static,
O2: 'static,
pub fn then_transform<O2>(
self,
next: &'static Transform<O, O2>,
) -> Transform<I, O2>where
I: 'static,
O: 'static,
O2: 'static,
Chain another transform to this transform
This is similar to then but takes a Transform instead of a Runnable.
Useful for composing pre-built transform pipelines.
The referenced transform must have a static lifetime (typically created with lazy_static!).
Sourcepub fn run(&self, input: I) -> Result<O, TransformError>
pub fn run(&self, input: I) -> Result<O, TransformError>
Execute this transform on the given input
Trait Implementations§
Auto Trait Implementations§
impl<I, O> Freeze for Transform<I, O>
impl<I, O> !RefUnwindSafe for Transform<I, O>
impl<I, O> Send for Transform<I, O>
impl<I, O> Sync for Transform<I, O>
impl<I, O> Unpin for Transform<I, O>
impl<I, O> UnsafeUnpin for Transform<I, O>
impl<I, O> !UnwindSafe for Transform<I, O>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more