This repository was archived by the owner on May 3, 2026. It is now read-only.
Repository navigation
Add explicit clone support to do-notation - #7
Merged
Merged
Conversation
This enables the user to explicitly clone values in do-notation. That is needed because otherwise one would not be able to carry such values along in do-notation for more than 2 statements. The reason is the parameter of `bind()`, which has to be `Fn`. If that parameter could be `FnOnce`, this issue would not exist, because a clean chain of moves would be possible. However, limiting the parameter for `bind()` would prevent implementing `Bind` for many structures that should be Monads, for instance `Vec`. With `bind()` taking `Fn`, the only option is to clone the to-be-captured values, either implicitly if they are `Copy`, or explicitly. This could of course be done before, but the syntax was convoluted. This change simplifies the syntax to a list of variables that one can add in front of the individual statements in do-notation.
Contributor
Author
|
As far as I can tell, the failing tests fail on master too. |
Owner
|
👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the implementation of explicit clones in do-notation, as discussed in issue #6. The issue should be resolved by this.
To reduce the amount of code duplication, the match arms in the macro that do not contain explicit clone parameters forward to those that contain them.
I really hope the macro doesn't have any ambiguity now. I think it should be fine, but my experience with macros in Rust is still limited, so it is possible that I'm overlooking something.