BoxBiTransformerOnce

Struct BoxBiTransformerOnce 

Source
pub struct BoxBiTransformerOnce<T, U, R> { /* private fields */ }
Expand description

BoxBiTransformerOnce - consuming bi-transformer wrapper based on Box<dyn FnOnce>

A bi-transformer wrapper that provides single ownership with one-time use semantics. Consumes self and both input values.

§Features

  • Based on: Box<dyn FnOnce(T, U) -> R>
  • Ownership: Single ownership, cannot be cloned
  • Reusability: Can only be called once (consumes self and inputs)
  • Thread Safety: Not thread-safe (no Send + Sync requirement)

§Author

Haixing Hu

Implementations§

Source§

impl<T, U, R> BoxBiTransformerOnce<T, U, R>
where T: 'static, U: 'static, R: 'static,

Source

pub fn new<F>(f: F) -> Self
where F: FnOnce(T, U) -> R + 'static,

Creates a new bi-transformer.

Wraps the provided closure in the appropriate smart pointer type for this bi-transformer implementation.

Source

pub fn new_with_name<F>(name: &str, f: F) -> Self
where F: FnOnce(T, U) -> R + 'static,

Creates a new named bi-transformer.

Wraps the provided closure and assigns it a name, which is useful for debugging and logging purposes.

Source

pub fn new_with_optional_name<F>(f: F, name: Option<String>) -> Self
where F: FnOnce(T, U) -> R + 'static,

Creates a new named bi-transformer with an optional name.

Wraps the provided closure and assigns it an optional name.

Source

pub fn name(&self) -> Option<&str>

Gets the name of this bi-transformer.

§Returns

Returns Some(&str) if a name was set, None otherwise.

Source

pub fn set_name(&mut self, name: &str)

Sets the name of this bi-transformer.

§Parameters
  • name - The name to set for this bi-transformer
Source

pub fn when<P>(self, predicate: P) -> BoxConditionalBiTransformerOnce<T, U, R>
where P: BiPredicate<T, U> + 'static,

Creates a conditional two-parameter transformer that executes based on bi-predicate result.

§Parameters
  • predicate - The bi-predicate to determine whether to execute the transformation operation
§Returns

Returns a conditional two-parameter transformer that only executes when the predicate returns true.

§Examples
use prism3_rust_function::transformers::*;

let bi_transformer = BoxBiTransformer::new({
    |key: &String, value: &i32| format!("{}: {}", key, value)
});

let conditional = bi_transformer.when(|key: &String, value: &i32| *value > 0);
assert_eq!(conditional.transform(&"test".to_string(), &5), "test: 5".to_string());  // transformed
assert_eq!(conditional.transform(&"test".to_string(), &-1), "test".to_string());    // identity (key unchanged)
Source

pub fn and_then<S, F>(self, after: F) -> BoxBiTransformerOnce<T, U, S>
where S: 'static, F: TransformerOnce<R, S> + 'static,

Chains execution with another two-parameter transformer, executing the current transformer first, then the subsequent transformer.

§Parameters
  • after - The subsequent two-parameter transformer to execute after the current transformer completes
§Returns

Returns a new two-parameter transformer that executes the current transformer and the subsequent transformer in sequence.

§Examples
use prism3_rust_function::transformers::*;

let bi_transformer1 = BoxBiTransformer::new({
    |key: &String, value: &i32| (key.clone(), *value + 1)
});

let bi_transformer2 = BoxBiTransformer::new({
    |key: &String, value: &i32| format!("{}: {}", key, value)
});

let chained = bi_transformer1.and_then(bi_transformer2);
let result = chained.transform(&"test".to_string(), &5);
assert_eq!(result, "test: 6"); // (value + 1) = 6
Source§

impl<T, U, R> BoxBiTransformerOnce<T, U, R>
where T: 'static, U: 'static, R: Clone + 'static,

Source

pub fn constant(value: R) -> BoxBiTransformerOnce<T, U, R>

Creates a constant bi-transformer

§Examples

/// rust /// use prism3_function::{BoxBiTransformerOnce, BiTransformer}; /// /// let constant = BoxBiTransformerOnce::constant("hello"); /// assert_eq!(constant.apply(123, 456), "hello"); ///

Trait Implementations§

Source§

impl<T, U, R> BiTransformerOnce<T, U, R> for BoxBiTransformerOnce<T, U, R>

Source§

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

Transforms two input values, consuming self and both inputs Read more
Source§

fn into_box(self) -> BoxBiTransformerOnce<T, U, R>
where T: 'static, U: 'static, R: 'static,

Converts to BoxBiTransformerOnce Read more
Source§

fn into_fn(self) -> impl FnOnce(T, U) -> R
where T: 'static, U: 'static, R: 'static,

Converts bi-transformer to a closure Read more
Source§

impl<T, U, R> Debug for BoxBiTransformerOnce<T, U, R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, U, R> Display for BoxBiTransformerOnce<T, U, R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, U, R> Freeze for BoxBiTransformerOnce<T, U, R>

§

impl<T, U, R> !RefUnwindSafe for BoxBiTransformerOnce<T, U, R>

§

impl<T, U, R> !Send for BoxBiTransformerOnce<T, U, R>

§

impl<T, U, R> !Sync for BoxBiTransformerOnce<T, U, R>

§

impl<T, U, R> Unpin for BoxBiTransformerOnce<T, U, R>

§

impl<T, U, R> !UnwindSafe for BoxBiTransformerOnce<T, U, R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<F, T> BinaryOperatorOnce<T> for F
where F: BiTransformerOnce<T, T, T>, T: 'static,