pub struct RcConditionalStatefulTransformer<T, R> { /* private fields */ }Expand description
RcConditionalStatefulTransformer struct
A single-threaded conditional transformer that only executes when a
predicate is satisfied. Uses RcStatefulTransformer and RcPredicate for shared
ownership within a single thread.
This type is typically created by calling RcStatefulTransformer::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 maps when predicate returns
true - No Lock Overhead: More efficient than
ArcConditionalStatefulTransformer
§Examples
use prism3_function::{StatefulTransformer, RcStatefulTransformer};
let mut transformer = RcStatefulTransformer::new(|x: i32| x * 2)
.when(|x: &i32| *x > 0)
.or_else(|x: i32| -x);
let mut transformer_clone = transformer.clone();
assert_eq!(transformer.apply(5), 10);
assert_eq!(transformer_clone.apply(-5), 5);§Author
Haixing Hu
Implementations§
Source§impl<T, R> RcConditionalStatefulTransformer<T, R>where
T: 'static,
R: 'static,
impl<T, R> RcConditionalStatefulTransformer<T, R>where
T: 'static,
R: 'static,
Sourcepub fn or_else<F>(&self, else_transformer: F) -> RcStatefulTransformer<T, R>where
F: StatefulTransformer<T, R> + 'static,
pub fn or_else<F>(&self, else_transformer: F) -> RcStatefulTransformer<T, R>where
F: StatefulTransformer<T, R> + 'static,
Trait Implementations§
Source§impl<T, R> Clone for RcConditionalStatefulTransformer<T, R>
impl<T, R> Clone for RcConditionalStatefulTransformer<T, R>
Source§impl<T, R> Debug for RcConditionalStatefulTransformer<T, R>
impl<T, R> Debug for RcConditionalStatefulTransformer<T, R>
Auto Trait Implementations§
impl<T, R> Freeze for RcConditionalStatefulTransformer<T, R>
impl<T, R> !RefUnwindSafe for RcConditionalStatefulTransformer<T, R>
impl<T, R> !Send for RcConditionalStatefulTransformer<T, R>
impl<T, R> !Sync for RcConditionalStatefulTransformer<T, R>
impl<T, R> Unpin for RcConditionalStatefulTransformer<T, R>
impl<T, R> !UnwindSafe for RcConditionalStatefulTransformer<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