pub struct RcStatefulTransformer<T, R> { /* private fields */ }Expand description
RcStatefulTransformer - single-threaded transformer wrapper
A single-threaded, clonable transformer wrapper optimized for scenarios that require sharing without thread-safety overhead.
§Features
- Based on:
Rc<RefCell<dyn FnMut(T) -> R>> - Ownership: Shared ownership via reference counting (non-atomic)
- Reusability: Can be called multiple times (each call consumes its input)
- Thread Safety: Not thread-safe (no
Send + Sync) - Clonable: Cheap cloning via
Rc::clone - Statefulness: Can modify internal state between calls
§Author
Haixing Hu
Implementations§
Source§impl<T, R> RcStatefulTransformer<T, R>where
T: 'static,
R: 'static,
impl<T, R> RcStatefulTransformer<T, R>where
T: 'static,
R: 'static,
Sourcepub fn new<F>(f: F) -> Selfwhere
F: FnMut(T) -> R + 'static,
pub fn new<F>(f: F) -> Selfwhere
F: FnMut(T) -> R + 'static,
Creates a new transformer.
Wraps the provided closure in the appropriate smart pointer type for this transformer implementation.
Sourcepub fn new_with_name<F>(name: &str, f: F) -> Selfwhere
F: FnMut(T) -> R + 'static,
pub fn new_with_name<F>(name: &str, f: F) -> Selfwhere
F: FnMut(T) -> R + 'static,
Creates a new named 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: FnMut(T) -> R + 'static,
pub fn new_with_optional_name<F>(f: F, name: Option<String>) -> Selfwhere
F: FnMut(T) -> R + 'static,
Creates a new named transformer with an optional name.
Wraps the provided closure and assigns it an optional name.
Sourcepub fn identity() -> RcStatefulTransformer<T, T>
pub fn identity() -> RcStatefulTransformer<T, T>
Creates an identity transformer.
Creates a transformer that returns the input value unchanged. Useful for default values or placeholder implementations.
§Returns
Returns a new transformer instance that returns the input unchanged.
pub fn when<P>(&self, predicate: P) -> RcConditionalStatefulTransformer<T, R>where
P: Predicate<T> + 'static,
pub fn and_then<S, F>(&self, after: F) -> RcStatefulTransformer<T, S>where
S: 'static,
F: StatefulTransformer<R, S> + 'static,
Source§impl<T, R> RcStatefulTransformer<T, R>where
T: 'static,
R: Clone + 'static,
impl<T, R> RcStatefulTransformer<T, R>where
T: 'static,
R: Clone + 'static,
Sourcepub fn constant(value: R) -> RcStatefulTransformer<T, R>
pub fn constant(value: R) -> RcStatefulTransformer<T, R>
Creates a constant transformer
§Examples
/// rust /// use prism3_function::{RcStatefulTransformer, StatefulTransformer}; /// /// let mut constant = RcStatefulTransformer::constant("hello"); /// assert_eq!(constant.apply(123), "hello"); ///
Trait Implementations§
Source§impl<T, R> Clone for RcStatefulTransformer<T, R>
impl<T, R> Clone for RcStatefulTransformer<T, R>
Source§impl<T, R> Debug for RcStatefulTransformer<T, R>
impl<T, R> Debug for RcStatefulTransformer<T, R>
Source§impl<T, R> Display for RcStatefulTransformer<T, R>
impl<T, R> Display for RcStatefulTransformer<T, R>
Source§impl<T, R> StatefulTransformer<T, R> for RcStatefulTransformer<T, R>
impl<T, R> StatefulTransformer<T, R> for RcStatefulTransformer<T, R>
Source§fn apply(&mut self, input: T) -> R
fn apply(&mut self, input: T) -> R
Source§fn into_box(self) -> BoxStatefulTransformer<T, R>where
T: 'static,
R: 'static,
fn into_box(self) -> BoxStatefulTransformer<T, R>where
T: 'static,
R: 'static,
Source§fn into_rc(self) -> RcStatefulTransformer<T, R>where
T: 'static,
R: 'static,
fn into_rc(self) -> RcStatefulTransformer<T, R>where
T: 'static,
R: 'static,
Source§fn into_fn(self) -> impl FnMut(T) -> R
fn into_fn(self) -> impl FnMut(T) -> R
FnMut(T) -> R Read moreSource§fn to_box(&self) -> BoxStatefulTransformer<T, R>where
T: 'static,
R: 'static,
fn to_box(&self) -> BoxStatefulTransformer<T, R>where
T: 'static,
R: 'static,
BoxStatefulTransformer. Read moreSource§fn to_rc(&self) -> RcStatefulTransformer<T, R>where
T: 'static,
R: 'static,
fn to_rc(&self) -> RcStatefulTransformer<T, R>where
T: 'static,
R: 'static,
RcStatefulTransformer. Read moreSource§fn to_fn(&self) -> impl FnMut(T) -> R
fn to_fn(&self) -> impl FnMut(T) -> R
FnMut(T) -> R). Read moreSource§fn into_once(self) -> BoxTransformerOnce<T, R>where
T: 'static,
R: 'static,
fn into_once(self) -> BoxTransformerOnce<T, R>where
T: 'static,
R: 'static,
BoxTransformerOnce. Read moreSource§fn to_once(&self) -> BoxTransformerOnce<T, R>where
T: 'static,
R: 'static,
fn to_once(&self) -> BoxTransformerOnce<T, R>where
T: 'static,
R: 'static,
BoxTransformerOnce from a cloned transformer Read more