pub struct RcConditionalTransformer<T, R> { /* private fields */ }Expand description
RcConditionalTransformer struct
A single-threaded conditional transformer that only executes when a
predicate is satisfied. Uses RcTransformer and RcPredicate for shared
ownership within a single thread.
This type is typically created by calling RcTransformer::when() and is
designed to work with the or_else() method to create if-then-else logic.
§Features
- Shared Ownership: Cloneable via
Rc, multiple owners allowed - Single-Threaded: Not thread-safe, cannot be sent across threads
- Conditional Execution: Only transforms when predicate returns
true - No Lock Overhead: More efficient than
ArcConditionalTransformer
§Examples
use prism3_function::{Transformer, RcTransformer};
let double = RcTransformer::new(|x: i32| x * 2);
let identity = RcTransformer::<i32, i32>::identity();
let conditional = double.when(|x: &i32| *x > 0).or_else(identity);
let conditional_clone = conditional.clone();
assert_eq!(conditional.apply(5), 10);
assert_eq!(conditional_clone.apply(-5), -5);§Author
Haixing Hu
Implementations§
Source§impl<T, R> RcConditionalTransformer<T, R>where
T: 'static,
R: 'static,
impl<T, R> RcConditionalTransformer<T, R>where
T: 'static,
R: 'static,
Sourcepub fn or_else<F>(&self, else_transformer: F) -> RcTransformer<T, R>where
F: Transformer<T, R> + 'static,
pub fn or_else<F>(&self, else_transformer: F) -> RcTransformer<T, R>where
F: Transformer<T, R> + 'static,
Trait Implementations§
Source§impl<T, R> Clone for RcConditionalTransformer<T, R>
impl<T, R> Clone for RcConditionalTransformer<T, R>
Source§impl<T, R> Debug for RcConditionalTransformer<T, R>
impl<T, R> Debug for RcConditionalTransformer<T, R>
Auto Trait Implementations§
impl<T, R> Freeze for RcConditionalTransformer<T, R>
impl<T, R> !RefUnwindSafe for RcConditionalTransformer<T, R>
impl<T, R> !Send for RcConditionalTransformer<T, R>
impl<T, R> !Sync for RcConditionalTransformer<T, R>
impl<T, R> Unpin for RcConditionalTransformer<T, R>
impl<T, R> !UnwindSafe for RcConditionalTransformer<T, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more