feat: sideffect/mutating should take FnMut over Fn

This commit is contained in:
Karolin Varner
2024-10-20 21:41:22 +02:00
parent 6321bb36fc
commit 48e629fff7

View File

@@ -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