ReadonlyBiConsumer

Trait ReadonlyBiConsumer 

Source
pub trait ReadonlyBiConsumer<T, U> {
    // Required methods
    fn accept(&self, first: &T, second: &U);
    fn into_box(self) -> BoxReadonlyBiConsumer<T, U>
       where Self: Sized + 'static,
             T: 'static,
             U: 'static;
    fn into_rc(self) -> RcReadonlyBiConsumer<T, U>
       where Self: Sized + 'static,
             T: 'static,
             U: 'static;
    fn into_arc(self) -> ArcReadonlyBiConsumer<T, U>
       where Self: Sized + Send + Sync + 'static,
             T: Send + Sync + 'static,
             U: Send + Sync + 'static;
    fn into_fn(self) -> impl Fn(&T, &U)
       where Self: Sized + 'static,
             T: 'static,
             U: 'static;
}
Expand description

ReadonlyBiConsumer trait - Unified readonly bi-consumer interface

Defines core behavior for all readonly bi-consumer types. Unlike BiConsumer, ReadonlyBiConsumer neither modifies its own state nor the input values, making it a fully immutable operation.

§Automatic Implementations

  • All closures implementing Fn(&T, &U)
  • BoxReadonlyBiConsumer<T, U>, ArcReadonlyBiConsumer<T, U>, RcReadonlyBiConsumer<T, U>

§Features

  • Unified Interface: All readonly bi-consumer types share the same accept method signature
  • Automatic Implementation: Closures automatically implement this trait with zero overhead
  • Type Conversions: Easy conversion between ownership models
  • Generic Programming: Write functions accepting any readonly bi-consumer type
  • No Interior Mutability: No need for Mutex or RefCell, more efficient

§Examples

use prism3_function::{ReadonlyBiConsumer, BoxReadonlyBiConsumer};

fn apply_consumer<C: ReadonlyBiConsumer<i32, i32>>(
    consumer: &C,
    a: &i32,
    b: &i32
) {
    consumer.accept(a, b);
}

let box_con = BoxReadonlyBiConsumer::new(|x: &i32, y: &i32| {
    println!("Sum: {}", x + y);
});
apply_consumer(&box_con, &5, &3);

§Author

Haixing Hu

Required Methods§

Source

fn accept(&self, first: &T, second: &U)

Performs the readonly consumption operation

Executes an operation on the given two references. The operation typically reads input values or produces side effects, but neither modifies the input values nor the consumer’s own state.

§Parameters
  • first - Reference to the first value to consume
  • second - Reference to the second value to consume
§Examples
use prism3_function::{ReadonlyBiConsumer, BoxReadonlyBiConsumer};

let consumer = BoxReadonlyBiConsumer::new(|x: &i32, y: &i32| {
    println!("Values: {}, {}", x, y);
});
consumer.accept(&5, &3);
Source

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

Converts to BoxReadonlyBiConsumer

⚠️ Consumes self: Original consumer becomes unavailable after calling this method.

§Returns

Returns the wrapped BoxReadonlyBiConsumer<T, U>

Source

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

Converts to RcReadonlyBiConsumer

⚠️ Consumes self: Original consumer becomes unavailable after calling this method.

§Returns

Returns the wrapped RcReadonlyBiConsumer<T, U>

Source

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

Converts to ArcReadonlyBiConsumer

⚠️ Consumes self: Original consumer becomes unavailable after calling this method.

§Returns

Returns the wrapped ArcReadonlyBiConsumer<T, U>

Source

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

Converts readonly bi-consumer to a closure

⚠️ Consumes self: Original consumer becomes unavailable after calling this method.

Converts the readonly bi-consumer to a closure usable with standard library methods requiring Fn.

§Returns

Returns a closure implementing Fn(&T, &U)

§Examples
use prism3_function::{ReadonlyBiConsumer, BoxReadonlyBiConsumer};

let consumer = BoxReadonlyBiConsumer::new(|x: &i32, y: &i32| {
    println!("Sum: {}", x + y);
});
let func = consumer.into_fn();
func(&5, &3);

Implementors§

Source§

impl<T, U> ReadonlyBiConsumer<T, U> for ArcReadonlyBiConsumer<T, U>

Source§

impl<T, U> ReadonlyBiConsumer<T, U> for BoxReadonlyBiConsumer<T, U>

Source§

impl<T, U> ReadonlyBiConsumer<T, U> for RcReadonlyBiConsumer<T, U>

Source§

impl<T, U, F> ReadonlyBiConsumer<T, U> for F
where F: Fn(&T, &U),

Implements ReadonlyBiConsumer for all Fn(&T, &U)