Skip to content

Commit

Permalink
Merge pull request #41 from lun3x/fn_mut
Browse files Browse the repository at this point in the history
Allow FnMut closures in modify_by_ methods
  • Loading branch information
lun3x authored Aug 30, 2023
2 parents 994ab48 + b1de553 commit 348285a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Order>;
fn remove_by_timestamp(&mut self, key: &u64) -> Option<Order>;
Expand Down
5 changes: 5 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -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)
==========================

Expand Down
4 changes: 2 additions & 2 deletions multi_index_map/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "multi_index_map"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
authors = ["Louis Wyborn <louiswyborn@gmail.com>"]
rust-version = "1.62"
Expand All @@ -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" }
Expand Down
7 changes: 6 additions & 1 deletion multi_index_map/tests/iter_after_modify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion multi_index_map_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "multi_index_map_derive"
version = "0.8.0"
version = "0.8.1"
edition = "2021"
authors = ["Louis Wyborn <louiswyborn@gmail.com>"]
rust-version = "1.62"
Expand Down
2 changes: 1 addition & 1 deletion multi_index_map_derive/src/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 348285a

Please sign in to comment.