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§
Sourcefn into_box(self) -> BoxBiTransformer<T, U, R>where
Self: Sized + 'static,
T: 'static,
U: 'static,
R: 'static,
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>
Sourcefn into_rc(self) -> RcBiTransformer<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,
Converts to RcBiTransformer
⚠️ Consumes self: The original bi-transformer becomes unavailable
after calling this method.
§Returns
Returns RcBiTransformer<T, U, R>
Sourcefn into_arc(self) -> ArcBiTransformer<T, U, R>
fn into_arc(self) -> ArcBiTransformer<T, U, R>
Converts to ArcBiTransformer
⚠️ Consumes self: The original bi-transformer becomes unavailable
after calling this method.
§Returns
Returns ArcBiTransformer<T, U, R>
Implementors§
impl<F, T, U, R> BiTransformer<T, U, R> for Fwhere
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