Fix borrowing issues#5
Merged
andrewhickman merged 4 commits intoandrewhickman:masterfrom Jul 7, 2021
SabrinaJewson:master
Merged
Fix borrowing issues#5andrewhickman merged 4 commits intoandrewhickman:masterfrom SabrinaJewson:master
andrewhickman merged 4 commits intoandrewhickman:masterfrom
SabrinaJewson:master
Conversation
Owner
|
Thanks for the PR! Looks like the sync version has the same issue. There's a bit of a tradeoff between supporting code like #[context("failed to parse config at `{}`", path.as_ref().display())]
pub fn parse_config(path: impl AsRef<Path>) -> anyhow::Result<u32> {
let text = read_to_string(path.as_ref())?;
Ok(text.parse()?)
}which fails when we use a move closure/async move block, and your example. Do you think a way to opt into the #[context(move, "context")]
async fn borrows(val: &mut u32) -> anyhow::Result<&u32> { |
Author
|
Oh, you're right - I didn't consider that case. |
async move block to fix borrowing issues
Author
|
I have updated the PR to add support for the |
Owner
|
Thanks for the PR! I'll release version 0.2.0 with these changes |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Previously, code like this would fail to compile:
With this error message:
This can be fixed by using an
async move {}block instead of anasync {}block.