mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-28 06:23:08 -08:00
feat: sideffect/mutating should take FnMut over Fn
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
pub fn mutating<T, F>(mut v: T, f: F) -> T
|
||||
where
|
||||
F: Fn(&mut T),
|
||||
F: FnMut(&mut T),
|
||||
{
|
||||
f(&mut v);
|
||||
v
|
||||
@@ -9,32 +9,32 @@ where
|
||||
pub trait MutatingExt {
|
||||
fn mutating<F>(self, f: F) -> Self
|
||||
where
|
||||
F: Fn(&mut Self);
|
||||
F: FnMut(&mut Self);
|
||||
fn mutating_mut<F>(&mut self, f: F) -> &mut Self
|
||||
where
|
||||
F: Fn(&mut Self);
|
||||
F: FnMut(&mut Self);
|
||||
}
|
||||
|
||||
impl<T> MutatingExt for T {
|
||||
fn mutating<F>(self, f: F) -> Self
|
||||
where
|
||||
F: Fn(&mut Self),
|
||||
F: FnMut(&mut Self),
|
||||
{
|
||||
mutating(self, f)
|
||||
}
|
||||
|
||||
fn mutating_mut<F>(&mut self, f: F) -> &mut Self
|
||||
fn mutating_mut<F>(&mut self, mut f: F) -> &mut Self
|
||||
where
|
||||
F: Fn(&mut Self),
|
||||
F: FnMut(&mut Self),
|
||||
{
|
||||
f(self);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sideeffect<T, F>(v: T, f: F) -> T
|
||||
pub fn sideeffect<T, F>(v: T, mut f: F) -> T
|
||||
where
|
||||
F: Fn(&T),
|
||||
F: FnMut(&T),
|
||||
{
|
||||
f(&v);
|
||||
v
|
||||
@@ -43,34 +43,34 @@ where
|
||||
pub trait SideffectExt {
|
||||
fn sideeffect<F>(self, f: F) -> Self
|
||||
where
|
||||
F: Fn(&Self);
|
||||
F: FnMut(&Self);
|
||||
fn sideeffect_ref<F>(&self, f: F) -> &Self
|
||||
where
|
||||
F: Fn(&Self);
|
||||
F: FnMut(&Self);
|
||||
fn sideeffect_mut<F>(&mut self, f: F) -> &mut Self
|
||||
where
|
||||
F: Fn(&Self);
|
||||
F: FnMut(&Self);
|
||||
}
|
||||
|
||||
impl<T> SideffectExt for T {
|
||||
fn sideeffect<F>(self, f: F) -> Self
|
||||
where
|
||||
F: Fn(&Self),
|
||||
F: FnMut(&Self),
|
||||
{
|
||||
sideeffect(self, f)
|
||||
}
|
||||
|
||||
fn sideeffect_ref<F>(&self, f: F) -> &Self
|
||||
fn sideeffect_ref<F>(&self, mut f: F) -> &Self
|
||||
where
|
||||
F: Fn(&Self),
|
||||
F: FnMut(&Self),
|
||||
{
|
||||
f(self);
|
||||
self
|
||||
}
|
||||
|
||||
fn sideeffect_mut<F>(&mut self, f: F) -> &mut Self
|
||||
fn sideeffect_mut<F>(&mut self, mut f: F) -> &mut Self
|
||||
where
|
||||
F: Fn(&Self),
|
||||
F: FnMut(&Self),
|
||||
{
|
||||
f(self);
|
||||
self
|
||||
|
||||
Reference in New Issue
Block a user