pub struct GenericChain<T> { /* private fields */ }
Expand description
Generic (works with all types) chaining wrapper
This wrapper’s API is very very simple, consisting of just 4 functions:
new
creates a new generic chainer (obviously :p)map
takes a closure that gets ownership of the inner value, and returns a new value, possibly of a different typewith_inner
takes a closure that can operate on a passed-in mutable reference to the inner valueinto_inner
will unwrap the struct and return the (possibly modified) contained value.
The idea is to provide a generic type that can give very basic and generic chaining abilities, useful for types that don’t have their own dedicated chainer.
This type also does not implement any traits, not even the chain ones provided by this module. The API really is just those 4 functions.
§Examples
Let’s pretend VecChain
doesn’t exist just for a moment…
// create the chain ...
let numbers = GenericChain::new(Vec::<i32>::new())
// ... chain push some numbers ...
.with_inner(|v| v.push(1))
.with_inner(|v| v.push(2))
.with_inner(|v| v.push(3))
.with_inner(|v| v.push(4))
.with_inner(|v| v.push(5))
// ... get back the inner vec, now with the pushed elements
.into_inner();
assert_eq!(&*numbers, &[1, 2, 3, 4, 5]);
Implementations§
Source§impl<T> GenericChain<T>
impl<T> GenericChain<T>
pub fn new(value: T) -> Self
pub fn map<T2>(self, f: impl FnOnce(T) -> T2) -> GenericChain<T2>
pub fn with_inner<F, Void>(self, f: F) -> Self
pub fn into_inner(self) -> T
Auto Trait Implementations§
impl<T> Freeze for GenericChain<T>where
T: Freeze,
impl<T> RefUnwindSafe for GenericChain<T>where
T: RefUnwindSafe,
impl<T> Send for GenericChain<T>where
T: Send,
impl<T> Sync for GenericChain<T>where
T: Sync,
impl<T> Unpin for GenericChain<T>where
T: Unpin,
impl<T> UnwindSafe for GenericChain<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> AcceptDefault<T> for T
impl<T> AcceptDefault<T> for T
fn unwrap_or_default(self) -> T
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