pub trait Transformer<T, R> {
// Required methods
fn transform(&self, input: T) -> R;
fn into_box(self) -> BoxTransformer<T, R>
where Self: Sized + 'static,
T: 'static,
R: 'static;
fn into_rc(self) -> RcTransformer<T, R>
where Self: Sized + 'static,
T: 'static,
R: 'static;
fn into_arc(self) -> ArcTransformer<T, R>
where Self: Sized + Send + Sync + 'static,
T: Send + Sync + 'static,
R: Send + Sync + 'static;
fn into_fn(self) -> impl Fn(T) -> R
where Self: Sized + 'static,
T: 'static,
R: 'static;
}Expand description
Transformer trait - transforms values from type T to type R
Defines the behavior of a transformation: converting a value of type T
to a value of type R by consuming the input. This is analogous to
Fn(T) -> R in Rust’s standard library.
§Type Parameters
T- The type of the input value (consumed)R- The type of the output value
§Author
Hu Haixing
Required Methods§
Sourcefn into_box(self) -> BoxTransformer<T, R>where
Self: Sized + 'static,
T: 'static,
R: 'static,
fn into_box(self) -> BoxTransformer<T, R>where
Self: Sized + 'static,
T: 'static,
R: 'static,
Converts to BoxTransformer
⚠️ Consumes self: The original transformer becomes unavailable
after calling this method.
§Returns
Returns BoxTransformer<T, R>
Sourcefn into_rc(self) -> RcTransformer<T, R>where
Self: Sized + 'static,
T: 'static,
R: 'static,
fn into_rc(self) -> RcTransformer<T, R>where
Self: Sized + 'static,
T: 'static,
R: 'static,
Converts to RcTransformer
⚠️ Consumes self: The original transformer becomes unavailable
after calling this method.
§Returns
Returns RcTransformer<T, R>
Sourcefn into_arc(self) -> ArcTransformer<T, R>
fn into_arc(self) -> ArcTransformer<T, R>
Converts to ArcTransformer
⚠️ Consumes self: The original transformer becomes unavailable
after calling this method.
§Returns
Returns ArcTransformer<T, R>
Implementors§
impl<F, T, R> Transformer<T, R> for Fwhere
F: Fn(T) -> R,
T: 'static,
R: 'static,
Implement Transformer<T, R> for any type that implements Fn(T) -> R
This allows closures and function pointers to be used directly with our Transformer trait without wrapping.
§Examples
use prism3_function::Transformer;
fn double(x: i32) -> i32 { x * 2 }
assert_eq!(double.transform(21), 42);
let triple = |x: i32| x * 3;
assert_eq!(triple.transform(14), 42);§Author
Hu Haixing