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§
Sourcefn into_box(self) -> BoxBiTransformerOnce<T, U, R>where
Self: Sized + 'static,
T: 'static,
U: 'static,
R: 'static,
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>
Sourcefn into_fn(self) -> impl FnOnce(T, U) -> Rwhere
Self: Sized + 'static,
T: 'static,
U: 'static,
R: 'static,
fn into_fn(self) -> impl FnOnce(T, U) -> Rwhere
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§
impl<F, T, U, R> BiTransformerOnce<T, U, R> for Fwhere
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