BiTransformer

Trait BiTransformer 

Source
pub trait BiTransformer<T, U, R> {
    // Required method
    fn apply(&self, first: T, second: U) -> R;

    // Provided methods
    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 { ... }
    fn into_once(self) -> BoxBiTransformerOnce<T, U, R>
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_box(&self) -> BoxBiTransformer<T, U, R>
       where Self: Sized + Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_rc(&self) -> RcBiTransformer<T, U, R>
       where Self: Sized + Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_arc(&self) -> ArcBiTransformer<T, U, R>
       where Self: Sized + Clone + Send + Sync + 'static,
             T: Send + Sync + 'static,
             U: Send + Sync + 'static,
             R: Send + Sync + 'static { ... }
    fn to_fn(&self) -> impl Fn(T, U) -> R
       where Self: Sized + Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_once(&self) -> BoxBiTransformerOnce<T, U, R>
       where Self: Clone + '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

Haixing Hu

Required Methods§

Source

fn apply(&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

Provided Methods§

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.

§Default Implementation

The default implementation wraps self in a Box and creates a BoxBiTransformer. Types can override this method to provide more efficient conversions.

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

§Default Implementation

The default implementation wraps self in an Rc and creates an RcBiTransformer. Types can override this method to provide more efficient conversions.

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

§Default Implementation

The default implementation wraps self in an Arc and creates an ArcBiTransformer. Types can override this method to provide more efficient conversions.

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

§Default Implementation

The default implementation creates a closure that captures self and calls its apply method. Types can override this method to provide more efficient conversions.

§Returns

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

Source

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

Convert to BiTransformerOnce

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

Converts a reusable bi-transformer to a one-time bi-transformer that consumes itself on use. This enables passing BiTransformer to functions that require BiTransformerOnce.

§Returns

Returns a BoxBiTransformerOnce<T, U, R>

Source

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

Non-consuming conversion to BoxBiTransformer using &self.

Default implementation clones self and delegates to into_box.

Source

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

Non-consuming conversion to RcBiTransformer using &self.

Default implementation clones self and delegates to into_rc.

Source

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

Non-consuming conversion to ArcBiTransformer using &self.

Default implementation clones self and delegates to into_arc.

Source

fn to_fn(&self) -> impl Fn(T, U) -> R
where Self: Sized + Clone + 'static, T: 'static, U: 'static, R: 'static,

Non-consuming conversion to a boxed function using &self.

Returns a Box<dyn Fn(T, U) -> R> that clones self and calls apply inside the boxed closure.

Source

fn to_once(&self) -> BoxBiTransformerOnce<T, U, R>
where Self: Clone + 'static, T: 'static, U: 'static, R: 'static,

Convert to BiTransformerOnce without consuming self

⚠️ Requires Clone: This method requires Self to implement Clone. Clones the current bi-transformer and converts the clone to a one-time bi-transformer.

§Returns

Returns a BoxBiTransformerOnce<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.apply(20, 22), 42);

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

§Author

Haixing Hu

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>