From 42ac3700e3c3e803eb438407b6a3c37f9279c020 Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Fri, 10 Sep 2021 14:47:13 +0100 Subject: [PATCH] Change bound in map/apply from Fn to FnMut (#136) * Change map/apply from Fn to FnMut * Update changelog --- CHANGELOG.md | 1 + src/int.rs | 24 ++++++++++++------------ src/vec/vec2.rs | 8 ++++---- src/vec/vec3.rs | 8 ++++---- src/vec/vec4.rs | 8 ++++---- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72c0a15..8e38109 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Add methods to scale `Rotor3` - Implement `Neg` for all `IVec` types +- Relax bound in `map` and `apply` from `Fn` to `FnMut` ## 0.8.1 diff --git a/src/int.rs b/src/int.rs index 4c5e554..05bfbf6 100644 --- a/src/int.rs +++ b/src/int.rs @@ -134,8 +134,8 @@ macro_rules! ivec2s { } #[inline] - pub fn map(&self, f: F) -> Self - where F: Fn($t) -> $t + pub fn map(&self, mut f: F) -> Self + where F: FnMut($t) -> $t { $n::new( f(self.x), @@ -144,8 +144,8 @@ macro_rules! ivec2s { } #[inline] - pub fn apply(&mut self, f: F) - where F: Fn($t) -> $t + pub fn apply(&mut self, mut f: F) + where F: FnMut($t) -> $t { self.x = f(self.x); self.y = f(self.y); @@ -577,8 +577,8 @@ macro_rules! ivec3s { } #[inline] - pub fn map(&self, f: F) -> Self - where F: Fn($t) -> $t + pub fn map(&self, mut f: F) -> Self + where F: FnMut($t) -> $t { $n::new( f(self.x), @@ -588,8 +588,8 @@ macro_rules! ivec3s { } #[inline] - pub fn apply(&mut self, f: F) - where F: Fn($t) -> $t + pub fn apply(&mut self, mut f: F) + where F: FnMut($t) -> $t { self.x = f(self.x); self.y = f(self.y); @@ -1001,8 +1001,8 @@ macro_rules! ivec4s { } #[inline] - pub fn map(&self, f: F) -> Self - where F: Fn($t) -> $t + pub fn map(&self, mut f: F) -> Self + where F: FnMut($t) -> $t { $n::new( f(self.x), @@ -1013,8 +1013,8 @@ macro_rules! ivec4s { } #[inline] - pub fn apply(&mut self, f: F) - where F: Fn($t) -> $t + pub fn apply(&mut self, mut f: F) + where F: FnMut($t) -> $t { self.x = f(self.x); self.y = f(self.y); diff --git a/src/vec/vec2.rs b/src/vec/vec2.rs index 679e79c..76a7249 100644 --- a/src/vec/vec2.rs +++ b/src/vec/vec2.rs @@ -176,8 +176,8 @@ macro_rules! vec2s { } #[inline] - pub fn map(&self, f: F) -> Self - where F: Fn($t) -> $t + pub fn map(&self, mut f: F) -> Self + where F: FnMut($t) -> $t { $n::new( f(self.x), @@ -186,8 +186,8 @@ macro_rules! vec2s { } #[inline] - pub fn apply(&mut self, f: F) - where F: Fn($t) -> $t + pub fn apply(&mut self, mut f: F) + where F: FnMut($t) -> $t { self.x = f(self.x); self.y = f(self.y); diff --git a/src/vec/vec3.rs b/src/vec/vec3.rs index eab9af4..4e7a6e1 100644 --- a/src/vec/vec3.rs +++ b/src/vec/vec3.rs @@ -224,8 +224,8 @@ macro_rules! vec3s { } #[inline] - pub fn map(&self, f: F) -> Self - where F: Fn($t) -> $t + pub fn map(&self, mut f: F) -> Self + where F: FnMut($t) -> $t { $n::new( f(self.x), @@ -235,8 +235,8 @@ macro_rules! vec3s { } #[inline] - pub fn apply(&mut self, f: F) - where F: Fn($t) -> $t + pub fn apply(&mut self, mut f: F) + where F: FnMut($t) -> $t { self.x = f(self.x); self.y = f(self.y); diff --git a/src/vec/vec4.rs b/src/vec/vec4.rs index ca19585..1029269 100644 --- a/src/vec/vec4.rs +++ b/src/vec/vec4.rs @@ -156,8 +156,8 @@ macro_rules! vec4s { } #[inline] - pub fn map(&self, f: F) -> Self - where F: Fn($t) -> $t + pub fn map(&self, mut f: F) -> Self + where F: FnMut($t) -> $t { $n::new( f(self.x), @@ -168,8 +168,8 @@ macro_rules! vec4s { } #[inline] - pub fn apply(&mut self, f: F) - where F: Fn($t) -> $t + pub fn apply(&mut self, mut f: F) + where F: FnMut($t) -> $t { self.x = f(self.x); self.y = f(self.y);