BiMutatingFunction

Trait BiMutatingFunction 

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

    // Provided methods
    fn into_box(self) -> BoxBiMutatingFunction<T, U, R>
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn into_rc(self) -> RcBiMutatingFunction<T, U, R>
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn into_arc(self) -> ArcBiMutatingFunction<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(&mut T, &mut U) -> R
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn into_once(self) -> BoxBiMutatingFunctionOnce<T, U, R>
       where Self: Sized + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_box(&self) -> BoxBiMutatingFunction<T, U, R>
       where Self: Sized + Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_rc(&self) -> RcBiMutatingFunction<T, U, R>
       where Self: Sized + Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_arc(&self) -> ArcBiMutatingFunction<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(&mut T, &mut U) -> R
       where Self: Sized + Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
    fn to_once(&self) -> BoxBiMutatingFunctionOnce<T, U, R>
       where Self: Clone + 'static,
             T: 'static,
             U: 'static,
             R: 'static { ... }
}
Expand description

BiMutatingFunction trait - performs operations on two mutable references

Defines the behavior of a bi-mutating-function: computing a value of type R from mutable references to types T and U, potentially modifying both inputs. This is analogous to Fn(&mut T, &mut U) -> R in Rust’s standard library.

§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

Applies the bi-mutating-function to two mutable references and returns a result

§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) -> BoxBiMutatingFunction<T, U, R>
where Self: Sized + 'static, T: 'static, U: 'static, R: 'static,

Converts to BoxBiMutatingFunction

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

§Default Implementation

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

§Returns

Returns BoxBiMutatingFunction<T, U, R>

Source

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

Converts to RcBiMutatingFunction

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

§Default Implementation

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

§Returns

Returns RcBiMutatingFunction<T, U, R>

Source

fn into_arc(self) -> ArcBiMutatingFunction<T, U, R>
where Self: Sized + Send + Sync + 'static, T: Send + Sync + 'static, U: Send + Sync + 'static, R: Send + Sync + 'static,

Converts to ArcBiMutatingFunction

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

§Default Implementation

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

§Returns

Returns ArcBiMutatingFunction<T, U, R>

Source

fn into_fn(self) -> impl Fn(&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.

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

Source

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

Converts to BiMutatingFunctionOnce

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

Converts a reusable bi-mutating-function to a one-time bi-mutating-function that consumes itself on use. This enables passing BiMutatingFunction to functions that require BiMutatingFunctionOnce.

§Returns

Returns a BoxBiMutatingFunctionOnce<T, U, R>

Source

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

Non-consuming conversion to BoxBiMutatingFunction using &self.

Default implementation clones self and delegates to into_box.

Source

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

Non-consuming conversion to RcBiMutatingFunction using &self.

Default implementation clones self and delegates to into_rc.

Source

fn to_arc(&self) -> ArcBiMutatingFunction<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 ArcBiMutatingFunction using &self.

Default implementation clones self and delegates to into_arc.

Source

fn to_fn(&self) -> impl Fn(&mut T, &mut 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(&mut T, &mut U) -> R> that clones self and calls apply inside the boxed closure.

Source

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

Convert to BiMutatingFunctionOnce without consuming self

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

§Returns

Returns a BoxBiMutatingFunctionOnce<T, U, R>

Implementors§

Source§

impl<T, U, R> BiMutatingFunction<T, U, R> for ArcBiMutatingFunction<T, U, R>

Source§

impl<T, U, R> BiMutatingFunction<T, U, R> for BoxBiMutatingFunction<T, U, R>

Source§

impl<T, U, R> BiMutatingFunction<T, U, R> for RcBiMutatingFunction<T, U, R>

Source§

impl<T, U, R, F> BiMutatingFunction<T, U, R> for F
where F: Fn(&mut T, &mut U) -> R, T: 'static, U: 'static, R: 'static,