Skip to main content

Transform

Struct Transform 

Source
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>

Source

pub fn identity() -> Self
where I: Clone + 'static, O: From<I> + 'static,

Create a new identity transform that passes input through unchanged

Note: This only works when I = O

Source

pub fn from_fn<F>(f: F) -> Self
where F: Fn(I) -> Result<O, TransformError> + Send + Sync + 'static,

Create a transform from a function

Source

pub fn then<O2, S>(self, stage: S) -> Transform<I, O2>
where S: Runnable<O, O2> + Send + Sync + 'static, I: 'static, O: 'static, O2: 'static,

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

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

Source

pub fn run(&self, input: I) -> Result<O, TransformError>

Execute this transform on the given input

Source§

impl<I, O> Transform<I, O>

Source

pub fn new<F>(f: F) -> Self
where F: Fn(I) -> Result<O, TransformError> + Send + Sync + 'static,

Create a new transform with no stages (useful as a starting point for composition)

Trait Implementations§

Source§

impl<I, O> Runnable<I, O> for Transform<I, O>
where I: 'static, O: 'static,

Source§

fn run(&self, input: I) -> Result<O, TransformError>

Execute this transformation on the input

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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more