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 + Syncrequirement)
§Author
Haixing Hu
Implementations§
Source§impl<T, U, R> BoxBiTransformerOnce<T, U, R>where
T: 'static,
U: 'static,
R: 'static,
impl<T, U, R> BoxBiTransformerOnce<T, U, R>where
T: 'static,
U: 'static,
R: 'static,
Sourcepub fn new<F>(f: F) -> Selfwhere
F: FnOnce(T, U) -> R + 'static,
pub fn new<F>(f: F) -> Selfwhere
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.
Sourcepub fn new_with_name<F>(name: &str, f: F) -> Selfwhere
F: FnOnce(T, U) -> R + 'static,
pub fn new_with_name<F>(name: &str, f: F) -> Selfwhere
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.
Sourcepub fn new_with_optional_name<F>(f: F, name: Option<String>) -> Selfwhere
F: FnOnce(T, U) -> R + 'static,
pub fn new_with_optional_name<F>(f: F, name: Option<String>) -> Selfwhere
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.
Sourcepub fn name(&self) -> Option<&str>
pub fn name(&self) -> Option<&str>
Gets the name of this bi-transformer.
§Returns
Returns Some(&str) if a name was set, None otherwise.
Sourcepub fn when<P>(self, predicate: P) -> BoxConditionalBiTransformerOnce<T, U, R>where
P: BiPredicate<T, U> + 'static,
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)Sourcepub fn and_then<S, F>(self, after: F) -> BoxBiTransformerOnce<T, U, S>where
S: 'static,
F: TransformerOnce<R, S> + 'static,
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) = 6Source§impl<T, U, R> BoxBiTransformerOnce<T, U, R>where
T: 'static,
U: 'static,
R: Clone + 'static,
impl<T, U, R> BoxBiTransformerOnce<T, U, R>where
T: 'static,
U: 'static,
R: Clone + 'static,
Sourcepub fn constant(value: R) -> BoxBiTransformerOnce<T, U, R>
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"); ///