BiFunctionOnce

Trait BiFunctionOnce 

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

    // Provided methods
    fn into_box(self) -> BoxBiFunctionOnce<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 { ... }
    fn to_box(&self) -> BoxBiFunctionOnce<T, U, R>
       where Self: Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_fn(&self) -> impl FnOnce(&T, &U) -> R
       where Self: Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
}
Expand description

BiFunctionOnce trait - consuming bi-function that takes references

Defines the behavior of a consuming bi-function: computing a value of type R from references to types T and U by taking ownership of self. This trait is analogous to FnOnce(&T, &U) -> R.

§Type Parameters

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

§Author

Haixing Hu

Required Methods§

Source

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

Computes output from two input references, consuming self

§Parameters
  • first - Reference to the first input value
  • second - Reference to the second input value
§Returns

The computed output value

Provided Methods§

Source

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

Converts to BoxBiFunctionOnce

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

§Returns

Returns BoxBiFunctionOnce<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-function to a closure

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

§Returns

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

Source

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

Converts bi-function to a boxed function pointer

📌 Borrows &self: The original bi-function remains usable after calling this method.

§Returns

Returns a boxed function pointer that implements FnOnce(&T, &U) -> R

§Examples
use prism3_function::BiFunctionOnce;

let add = |x: &i32, y: &i32| *x + *y;
let func = add.to_box();
assert_eq!(func.apply(&20, &22), 42);
Source

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

Converts bi-function to a closure

📌 Borrows &self: The original bi-function remains usable after calling this method.

§Returns

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

§Examples
use prism3_function::BiFunctionOnce;

let add = |x: &i32, y: &i32| *x + *y;
let func = add.to_fn();
assert_eq!(func(&20, &22), 42);

Implementors§

Source§

impl<F, T, U, R> BiFunctionOnce<T, U, R> for F
where F: FnOnce(&T, &U) -> R,

Source§

impl<T, U, R> BiFunctionOnce<T, U, R> for BoxBiFunctionOnce<T, U, R>