BiMutatingFunctionOnce

Trait BiMutatingFunctionOnce 

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

    // Provided methods
    fn into_box(self) -> BoxBiMutatingFunctionOnce<T, U, R>
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn into_fn(self) -> impl FnOnce(&mut T, &mut U) -> R
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_box(&self) -> BoxBiMutatingFunctionOnce<T, U, R>
       where Self: Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_fn(&self) -> impl FnOnce(&mut T, &mut U) -> R
       where Self: Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
}
Expand description

BiMutatingFunctionOnce trait - consuming bi-mutating-function that takes mutable references

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

§Type Parameters

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

§Author

Haixing Hu

Required Methods§

Source

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

Computes output from two mutable references, consuming self

§Parameters
  • first - Mutable reference to the first input value
  • second - Mutable reference to the second input value
§Returns

The computed output value

Provided Methods§

Source

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

Converts to BoxBiMutatingFunctionOnce

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

§Returns

Returns BoxBiMutatingFunctionOnce<T, U, R>

Source

fn into_fn(self) -> impl FnOnce(&mut T, &mut U) -> R
where Self: Sized + 'static, T: 'static, U: 'static, R: 'static,

Converts bi-mutating-function to a closure

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

§Returns

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

Source

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

Converts bi-mutating-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(&mut T, &mut U) -> R

§Examples
use prism3_function::BiMutatingFunctionOnce;

let swap_and_sum = |x: &mut i32, y: &mut i32| {
    let temp = *x;
    *x = *y;
    *y = temp;
    *x + *y
};
let func = swap_and_sum.to_box();
let mut a = 20;
let mut b = 22;
assert_eq!(func.apply(&mut a, &mut b), 42);
Source

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

Converts bi-mutating-function to a closure

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

§Returns

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

§Examples
use prism3_function::BiMutatingFunctionOnce;

let swap_and_sum = |x: &mut i32, y: &mut i32| {
    let temp = *x;
    *x = *y;
    *y = temp;
    *x + *y
};
let func = swap_and_sum.to_fn();
let mut a = 20;
let mut b = 22;
assert_eq!(func(&mut a, &mut b), 42);

Implementors§

Source§

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

Source§

impl<T, U, R> BiMutatingFunctionOnce<T, U, R> for BoxBiMutatingFunctionOnce<T, U, R>