BiFunction

Trait BiFunction 

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

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

BiFunction trait - computes output from two input references

Defines the behavior of a bi-function: computing a value of type R from references to types T and U without consuming the inputs. This is analogous to Fn(&T, &U) -> R in Rust’s standard library, similar to Java’s BiFunction<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

Applies the bi-function to two input references to produce an output value

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

Converts to BoxBiFunction

⚠️ 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 BoxBiFunction. Types can override this method to provide more efficient conversions.

§Returns

Returns BoxBiFunction<T, U, R>

Source

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

Converts to RcBiFunction

⚠️ 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 RcBiFunction. Types can override this method to provide more efficient conversions.

§Returns

Returns RcBiFunction<T, U, R>

Source

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

Converts to ArcBiFunction

⚠️ 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 ArcBiFunction. Types can override this method to provide more efficient conversions.

§Returns

Returns ArcBiFunction<T, U, R>

Source

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

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

Source

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

Converts to BiFunctionOnce

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

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

§Returns

Returns a BoxBiFunctionOnce<T, U, R>

Source

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

Non-consuming conversion to BoxBiFunction using &self.

Default implementation clones self and delegates to into_box.

Source

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

Non-consuming conversion to RcBiFunction using &self.

Default implementation clones self and delegates to into_rc.

Source

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

Default implementation clones self and delegates to into_arc.

Source

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

Source

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

Convert to BiFunctionOnce 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 BoxBiFunctionOnce<T, U, R>

Implementors§

Source§

impl<T, U, R> BiFunction<T, U, R> for ArcBiFunction<T, U, R>

Source§

impl<T, U, R> BiFunction<T, U, R> for BoxBiFunction<T, U, R>

Source§

impl<T, U, R> BiFunction<T, U, R> for RcBiFunction<T, U, R>

Source§

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