pub trait TransformerOnce<T, R> {
// Required method
fn apply(self, input: T) -> R;
// Provided methods
fn into_box(self) -> BoxTransformerOnce<T, R>
where Self: Sized + 'static,
T: 'static,
R: 'static { ... }
fn into_fn(self) -> impl FnOnce(T) -> R
where Self: Sized + 'static,
T: 'static,
R: 'static { ... }
fn to_box(&self) -> BoxTransformerOnce<T, R>
where Self: Clone + 'static,
T: 'static,
R: 'static { ... }
fn to_fn(&self) -> impl FnOnce(T) -> R
where Self: Clone + 'static,
T: 'static,
R: 'static { ... }
}Expand description
TransformerOnce trait - consuming transformation that takes ownership
Defines the behavior of a consuming transformer: converting a value of
type T to a value of type R by taking ownership of both self and the
input. This trait is analogous to FnOnce(T) -> R.
§Type Parameters
T- The type of the input value (consumed)R- The type of the output value
§Author
Haixing Hu
Required Methods§
Provided Methods§
Sourcefn into_box(self) -> BoxTransformerOnce<T, R>where
Self: Sized + 'static,
T: 'static,
R: 'static,
fn into_box(self) -> BoxTransformerOnce<T, R>where
Self: Sized + 'static,
T: 'static,
R: 'static,
Converts to BoxTransformerOnce
⚠️ Consumes self: The original transformer becomes unavailable
after calling this method.
§Returns
Returns BoxTransformerOnce<T, R>
§Examples
use prism3_function::TransformerOnce;
let double = |x: i32| x * 2;
let boxed = double.into_box();
assert_eq!(boxed.apply(21), 42);Sourcefn into_fn(self) -> impl FnOnce(T) -> Rwhere
Self: Sized + 'static,
T: 'static,
R: 'static,
fn into_fn(self) -> impl FnOnce(T) -> Rwhere
Self: Sized + 'static,
T: 'static,
R: 'static,
Converts transformer to a closure
⚠️ Consumes self: The original transformer becomes unavailable
after calling this method.
§Returns
Returns a closure that implements FnOnce(T) -> R
§Examples
use prism3_function::TransformerOnce;
let double = |x: i32| x * 2;
let func = double.into_fn();
assert_eq!(func(21), 42);Sourcefn to_box(&self) -> BoxTransformerOnce<T, R>where
Self: Clone + 'static,
T: 'static,
R: 'static,
fn to_box(&self) -> BoxTransformerOnce<T, R>where
Self: Clone + 'static,
T: 'static,
R: 'static,
Converts to BoxTransformerOnce without consuming self
📌 Borrows &self: The original transformer remains usable
after calling this method.
§Default Implementation
The default implementation creates a new BoxTransformerOnce that
captures a clone. Types implementing Clone can override this method
to provide more efficient conversions.
§Returns
Returns BoxTransformerOnce<T, R>
§Examples
use prism3_function::TransformerOnce;
let double = |x: i32| x * 2;
let boxed = double.to_box();
assert_eq!(boxed.apply(21), 42);Sourcefn to_fn(&self) -> impl FnOnce(T) -> Rwhere
Self: Clone + 'static,
T: 'static,
R: 'static,
fn to_fn(&self) -> impl FnOnce(T) -> Rwhere
Self: Clone + 'static,
T: 'static,
R: 'static,
Converts transformer to a closure without consuming self
📌 Borrows &self: The original transformer remains usable
after calling this method.
§Default Implementation
The default implementation creates a closure that captures a
clone of self and calls its transform method. Types can
override this method to provide more efficient conversions.
§Returns
Returns a closure that implements FnOnce(T) -> R
§Examples
use prism3_function::TransformerOnce;
let double = |x: i32| x * 2;
let func = double.to_fn();
assert_eq!(func(21), 42);