From 4deb59de09387bd4e5c65f00a171f91279203c79 Mon Sep 17 00:00:00 2001 From: Louis Wyborn Date: Wed, 30 Aug 2023 11:02:53 +0100 Subject: [PATCH 1/3] Allow FnMut closures in modify_by_ --- multi_index_map/tests/iter_after_modify.rs | 7 ++++++- multi_index_map_derive/src/generators.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/multi_index_map/tests/iter_after_modify.rs b/multi_index_map/tests/iter_after_modify.rs index fec32d7..a331768 100644 --- a/multi_index_map/tests/iter_after_modify.rs +++ b/multi_index_map/tests/iter_after_modify.rs @@ -51,10 +51,15 @@ fn iter_after_modify() { assert_eq!(it.next().unwrap().order_id, 1); } + let mut s = "test".to_string(); + map.modify_by_order_id(&1, |o| { - o.timestamp = 0; + s = "p".to_string(); + o.timestamp = 4; }); + assert_eq!(s, "p"); + { let mut it = map.iter_by_timestamp(); assert_eq!(it.next().unwrap().order_id, 1); diff --git a/multi_index_map_derive/src/generators.rs b/multi_index_map_derive/src/generators.rs index f5f8869..2bedfbf 100644 --- a/multi_index_map_derive/src/generators.rs +++ b/multi_index_map_derive/src/generators.rs @@ -533,7 +533,7 @@ fn generate_field_modifier( #field_vis fn #modifier_name( &mut self, key: &#field_type, - f: impl Fn(&mut #element_name) + mut f: impl FnMut(&mut #element_name) ) -> Vec<&#element_name> { let idxs = match self.#index_name.get(key) { Some(container) => container.clone(), From 470a137fc3672738d9e1b9c38e1381947eb934ea Mon Sep 17 00:00:00 2001 From: Louis Wyborn Date: Wed, 30 Aug 2023 11:03:35 +0100 Subject: [PATCH 2/3] Update readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dd8b894..6ed45b4 100644 --- a/README.md +++ b/README.md @@ -167,11 +167,11 @@ impl MultiIndexOrderMap { fn update_by_order_id(&mut self, key: &u32, f: impl FnOnce(&mut bool, &mut u64)) -> Option<&Order>; fn update_by_timestamp(&mut self, key: &u64, f: impl FnOnce(&mut bool, &mut u64)) -> Option<&Order>; - fn update_by_trader_name(&mut self, key: &String, f: impl FnOnce(&mut bool, &mut u64)) -> Vec<&Order>; + fn update_by_trader_name(&mut self, key: &String, f: impl FnMut(&mut bool, &mut u64)) -> Vec<&Order>; fn modify_by_order_id(&mut self, key: &u32, f: impl FnOnce(&mut Order)) -> Option<&Order>; fn modify_by_timestamp(&mut self, key: &u64, f: impl FnOnce(&mut Order)) -> Option<&Order>; - fn modify_by_trader_name(&mut self, key: &String, f: impl Fn(&mut Order)) -> Vec<&Order>; + fn modify_by_trader_name(&mut self, key: &String, f: impl FnMut(&mut Order)) -> Vec<&Order>; fn remove_by_order_id(&mut self, key: &u32) -> Option; fn remove_by_timestamp(&mut self, key: &u64) -> Option; From b1de55364036ff37b054bb4be0d01d9e51f93e46 Mon Sep 17 00:00:00 2001 From: Louis Wyborn Date: Wed, 30 Aug 2023 11:04:26 +0100 Subject: [PATCH 3/3] Update releases.md --- RELEASES.md | 5 +++++ multi_index_map/Cargo.toml | 4 ++-- multi_index_map_derive/Cargo.toml | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/RELEASES.md b/RELEASES.md index 57b83e0..978b667 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,8 @@ +Version 0.8.1 (2023-08-30) +========================== + +- Allow FnMut closures in `modify_by_` methods. + Version 0.8.0 (2023-08-30) ========================== diff --git a/multi_index_map/Cargo.toml b/multi_index_map/Cargo.toml index b716bde..ec4ea69 100644 --- a/multi_index_map/Cargo.toml +++ b/multi_index_map/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "multi_index_map" -version = "0.8.0" +version = "0.8.1" edition = "2021" authors = ["Louis Wyborn "] rust-version = "1.62" @@ -14,7 +14,7 @@ readme = "README.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -multi_index_map_derive = { version = "0.8.0", path = "../multi_index_map_derive" } +multi_index_map_derive = { version = "0.8.1", path = "../multi_index_map_derive" } # Used as the backing store of all the elements. slab = { version = "0.4" } diff --git a/multi_index_map_derive/Cargo.toml b/multi_index_map_derive/Cargo.toml index fe55c43..cfd93b0 100644 --- a/multi_index_map_derive/Cargo.toml +++ b/multi_index_map_derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "multi_index_map_derive" -version = "0.8.0" +version = "0.8.1" edition = "2021" authors = ["Louis Wyborn "] rust-version = "1.62"