Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use fnmut for functions on map values #34

Merged
merged 1 commit into from
Aug 2, 2018
Merged

Conversation

dwightguth
Copy link

This improves the fix for issue #7 in order to allow users to write functions over map values that can record state. This is useful if you want to report an error if you are unioning two maps and discover conflicting keys. You can write something like:

let mut error = false;
let union = m1.clone().union_with(m2.clone(), |v1, _| { error = true; v1 });
if error {
  // do something
}

This was not possible previously because of the constraint Fn on the function argument to union_with instead of FnMut. Note that because Fn implements FnMut, this is a strict superset of the functionality accepted previously and should be fully backwards compatible to the best of my understanding.

@bodil
Copy link
Owner

bodil commented Aug 2, 2018

Huh, I was sure I'd done this already, it must have gotten lost somewhere... Thanks, merging!

@bodil bodil merged commit fec1f06 into bodil:master Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants