pub struct RcTransformer<T, R> { /* private fields */ }Expand description
RcTransformer - single-threaded transformer wrapper
A single-threaded, clonable transformer wrapper optimized for scenarios that require sharing without thread-safety overhead.
§Features
- Based on:
Rc<dyn Fn(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
§Author
Haixing Hu
Implementations§
Source§impl<T, R> RcTransformer<T, R>where
T: 'static,
R: 'static,
impl<T, R> RcTransformer<T, R>where
T: 'static,
R: 'static,
Sourcepub fn new<F>(f: F) -> Selfwhere
F: Fn(T) -> R + 'static,
pub fn new<F>(f: F) -> Selfwhere
F: Fn(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: Fn(T) -> R + 'static,
pub fn new_with_name<F>(name: &str, f: F) -> Selfwhere
F: Fn(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: Fn(T) -> R + 'static,
pub fn new_with_optional_name<F>(f: F, name: Option<String>) -> Selfwhere
F: Fn(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() -> RcTransformer<T, T>
pub fn identity() -> RcTransformer<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) -> RcConditionalTransformer<T, R>where
P: Predicate<T> + 'static,
pub fn and_then<S, F>(&self, after: F) -> RcTransformer<T, S>where
S: 'static,
F: Transformer<R, S> + 'static,
Source§impl<T, R> RcTransformer<T, R>where
T: 'static,
R: Clone + 'static,
impl<T, R> RcTransformer<T, R>where
T: 'static,
R: Clone + 'static,
Sourcepub fn constant(value: R) -> RcTransformer<T, R>
pub fn constant(value: R) -> RcTransformer<T, R>
Creates a constant transformer
§Examples
/// rust /// use prism3_function::{RcTransformer, Transformer}; /// /// let constant = RcTransformer::constant("hello"); /// assert_eq!(constant.apply(123), "hello"); ///
Trait Implementations§
Source§impl<T, R> Clone for RcTransformer<T, R>
impl<T, R> Clone for RcTransformer<T, R>
Source§impl<T, R> Debug for RcTransformer<T, R>
impl<T, R> Debug for RcTransformer<T, R>
Source§impl<T, R> Display for RcTransformer<T, R>
impl<T, R> Display for RcTransformer<T, R>
Source§impl<T, R> Transformer<T, R> for RcTransformer<T, R>
impl<T, R> Transformer<T, R> for RcTransformer<T, R>
Source§fn apply(&self, input: T) -> R
fn apply(&self, input: T) -> R
Source§fn into_box(self) -> BoxTransformer<T, R>where
T: 'static,
R: 'static,
fn into_box(self) -> BoxTransformer<T, R>where
T: 'static,
R: 'static,
Source§fn into_rc(self) -> RcTransformer<T, R>where
T: 'static,
R: 'static,
fn into_rc(self) -> RcTransformer<T, R>where
T: 'static,
R: 'static,
Source§fn to_box(&self) -> BoxTransformer<T, R>where
T: 'static,
R: 'static,
fn to_box(&self) -> BoxTransformer<T, R>where
T: 'static,
R: 'static,
Source§fn to_rc(&self) -> RcTransformer<T, R>where
T: 'static,
R: 'static,
fn to_rc(&self) -> RcTransformer<T, R>where
T: 'static,
R: 'static,
Source§fn to_fn(&self) -> impl Fn(T) -> R
fn to_fn(&self) -> impl Fn(T) -> R
Source§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 without consuming self Read more