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
|
pub fn mutating<T, F>(mut v: T, f: F) -> T
|
||||||
where
|
where
|
||||||
F: Fn(&mut T),
|
F: FnMut(&mut T),
|
||||||
{
|
{
|
||||||
f(&mut v);
|
f(&mut v);
|
||||||
v
|
v
|
||||||
@@ -9,32 +9,32 @@ where
|
|||||||
pub trait MutatingExt {
|
pub trait MutatingExt {
|
||||||
fn mutating<F>(self, f: F) -> Self
|
fn mutating<F>(self, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(&mut Self);
|
F: FnMut(&mut Self);
|
||||||
fn mutating_mut<F>(&mut self, f: F) -> &mut Self
|
fn mutating_mut<F>(&mut self, f: F) -> &mut Self
|
||||||
where
|
where
|
||||||
F: Fn(&mut Self);
|
F: FnMut(&mut Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> MutatingExt for T {
|
impl<T> MutatingExt for T {
|
||||||
fn mutating<F>(self, f: F) -> Self
|
fn mutating<F>(self, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(&mut Self),
|
F: FnMut(&mut Self),
|
||||||
{
|
{
|
||||||
mutating(self, f)
|
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
|
where
|
||||||
F: Fn(&mut Self),
|
F: FnMut(&mut Self),
|
||||||
{
|
{
|
||||||
f(self);
|
f(self);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sideeffect<T, F>(v: T, f: F) -> T
|
pub fn sideeffect<T, F>(v: T, mut f: F) -> T
|
||||||
where
|
where
|
||||||
F: Fn(&T),
|
F: FnMut(&T),
|
||||||
{
|
{
|
||||||
f(&v);
|
f(&v);
|
||||||
v
|
v
|
||||||
@@ -43,34 +43,34 @@ where
|
|||||||
pub trait SideffectExt {
|
pub trait SideffectExt {
|
||||||
fn sideeffect<F>(self, f: F) -> Self
|
fn sideeffect<F>(self, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(&Self);
|
F: FnMut(&Self);
|
||||||
fn sideeffect_ref<F>(&self, f: F) -> &Self
|
fn sideeffect_ref<F>(&self, f: F) -> &Self
|
||||||
where
|
where
|
||||||
F: Fn(&Self);
|
F: FnMut(&Self);
|
||||||
fn sideeffect_mut<F>(&mut self, f: F) -> &mut Self
|
fn sideeffect_mut<F>(&mut self, f: F) -> &mut Self
|
||||||
where
|
where
|
||||||
F: Fn(&Self);
|
F: FnMut(&Self);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> SideffectExt for T {
|
impl<T> SideffectExt for T {
|
||||||
fn sideeffect<F>(self, f: F) -> Self
|
fn sideeffect<F>(self, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: Fn(&Self),
|
F: FnMut(&Self),
|
||||||
{
|
{
|
||||||
sideeffect(self, f)
|
sideeffect(self, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sideeffect_ref<F>(&self, f: F) -> &Self
|
fn sideeffect_ref<F>(&self, mut f: F) -> &Self
|
||||||
where
|
where
|
||||||
F: Fn(&Self),
|
F: FnMut(&Self),
|
||||||
{
|
{
|
||||||
f(self);
|
f(self);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sideeffect_mut<F>(&mut self, f: F) -> &mut Self
|
fn sideeffect_mut<F>(&mut self, mut f: F) -> &mut Self
|
||||||
where
|
where
|
||||||
F: Fn(&Self),
|
F: FnMut(&Self),
|
||||||
{
|
{
|
||||||
f(self);
|
f(self);
|
||||||
self
|
self
|
||||||
|
|||||||
Reference in New Issue
Block a user