BiTransformerOnce

Trait BiTransformerOnce 

Source
pub trait BiTransformerOnce<T, U, R> {
    // Required methods
    fn transform(self, first: T, second: U) -> R;
    fn into_box(self) -> BoxBiTransformerOnce<T, U, R>
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static;
    fn into_fn(self) -> impl FnOnce(T, U) -> R
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static;
}
Expand description

BiTransformerOnce trait - consuming bi-transformation that takes ownership

Defines the behavior of a consuming bi-transformer: converting two values of types T and U to a value of type R by taking ownership of self and both inputs. This trait is analogous to FnOnce(T, U) -> R.

§Type Parameters

  • T - The type of the first input value (consumed)
  • U - The type of the second input value (consumed)
  • R - The type of the output value

§Author

Hu Haixing

Required Methods§

Source

fn transform(self, first: T, second: U) -> R

Transforms two input values, consuming self and both inputs

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

The transformed output value

Source

fn into_box(self) -> BoxBiTransformerOnce<T, U, R>
where Self: Sized + 'static, T: 'static, U: 'static, R: 'static,

Converts to BoxBiTransformerOnce

⚠️ Consumes self: The original bi-transformer becomes unavailable after calling this method.

§Returns

Returns BoxBiTransformerOnce<T, U, R>

Source

fn into_fn(self) -> impl FnOnce(T, U) -> R
where Self: Sized + 'static, T: 'static, U: 'static, R: 'static,

Converts bi-transformer to a closure

⚠️ Consumes self: The original bi-transformer becomes unavailable after calling this method.

§Returns

Returns a closure that implements FnOnce(T, U) -> R

Implementors§

Source§

impl<F, T, U, R> BiTransformerOnce<T, U, R> for F
where F: FnOnce(T, U) -> R, T: 'static, U: 'static, R: 'static,

Implement BiTransformerOnce<T, U, R> for any type that implements FnOnce(T, U) -> R

This allows once-callable closures and function pointers to be used directly with our BiTransformerOnce trait without wrapping.

§Examples

use prism3_function::BiTransformerOnce;

fn add(x: i32, y: i32) -> i32 {
    x + y
}

assert_eq!(add.transform(20, 22), 42);

let owned_x = String::from("hello");
let owned_y = String::from("world");
let concat = |x: String, y: String| {
    format!("{} {}", x, y)
};
assert_eq!(concat.transform(owned_x, owned_y), "hello world");

§Author

Hu Haixing

Source§

impl<T, U, R> BiTransformerOnce<T, U, R> for BoxBiTransformerOnce<T, U, R>