BiTransformer

Trait BiTransformer 

Source
pub trait BiTransformer<T, U, R> {
    // Required methods
    fn transform(&self, first: T, second: U) -> R;
    fn into_box(self) -> BoxBiTransformer<T, U, R>
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static;
    fn into_rc(self) -> RcBiTransformer<T, U, R>
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static;
    fn into_arc(self) -> ArcBiTransformer<T, U, R>
       where Self: Sized + Send + Sync + 'static,
             T: Send + Sync + 'static,
             U: Send + Sync + 'static,
             R: Send + Sync + 'static;
    fn into_fn(self) -> impl Fn(T, U) -> R
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static;
}
Expand description

BiTransformer trait - transforms two values to produce a result

Defines the behavior of a bi-transformation: converting two values of types T and U to a value of type R by consuming the inputs. This is analogous to Fn(T, U) -> R in Rust’s standard library.

§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 to produce an output value

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

The transformed output value

Source

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

Converts to BoxBiTransformer

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

§Returns

Returns BoxBiTransformer<T, U, R>

Source

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

Converts to RcBiTransformer

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

§Returns

Returns RcBiTransformer<T, U, R>

Source

fn into_arc(self) -> ArcBiTransformer<T, U, R>
where Self: Sized + Send + Sync + 'static, T: Send + Sync + 'static, U: Send + Sync + 'static, R: Send + Sync + 'static,

Converts to ArcBiTransformer

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

§Returns

Returns ArcBiTransformer<T, U, R>

Source

fn into_fn(self) -> impl Fn(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 Fn(T, U) -> R

Implementors§

Source§

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

Implement BiTransformer<T, U, R> for any type that implements Fn(T, U) -> R

This allows closures and function pointers to be used directly with our BiTransformer trait without wrapping.

§Examples

use prism3_function::BiTransformer;

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

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

let multiply = |x: i32, y: i32| x * y;
assert_eq!(multiply.transform(6, 7), 42);

§Author

Hu Haixing

Source§

impl<T, U, R> BiTransformer<T, U, R> for ArcBiTransformer<T, U, R>

Source§

impl<T, U, R> BiTransformer<T, U, R> for BoxBiTransformer<T, U, R>

Source§

impl<T, U, R> BiTransformer<T, U, R> for RcBiTransformer<T, U, R>