tap
tap copied to clipboard
A version of pipe that gets a self and returns nothing consuming object
Often when dealing with locks or something I tend to just do
lock.tap_mut(...)
which gets a &mut self
however this triggers must use warnings.
Alternatively i use pipe
to solve this issue however by design it is for mapping something to something else so this would be abusing pipe
.
I suggest adding a method lets say with
which would consume the value and return nothing
lock.with(|mut lock|{...})
I can create a pr if maintainers approve the naming and the idea
PS. Thanks for this amazing library which became basically a utility for all my rust projects
I've done something like this in my own projects and I called it "ignore". Basically the whole trait is like:
trait Ignored: Sized {
fn ignore(self) {}
}
impl<T> Ignored for T{}
Alternatively, if you wanted to do some side effect, you could also implement another trait like:
trait Effect: Sized {
fn effect<F>(self, f: F)
where F: FnOnce(Self)
{
f(self);
}
}
impl<T> Effect for T{}