TransformerOnce

Trait TransformerOnce 

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

Source

fn apply(self, input: T) -> R

Transforms the input value, consuming both self and input

§Parameters
  • input - The input value (consumed)
§Returns

The transformed output value

Provided Methods§

Source

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

fn into_fn(self) -> impl FnOnce(T) -> R
where 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);
Source

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

fn to_fn(&self) -> impl FnOnce(T) -> R
where 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);

Implementors§

Source§

impl<F, T, R> TransformerOnce<T, R> for F
where F: FnOnce(T) -> R,

Source§

impl<T, R> TransformerOnce<T, R> for BoxTransformerOnce<T, R>