-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix borrowing issues #5
Conversation
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> { |
Oh, you're right - I didn't consider that case. |
async move
block to fix borrowing issues
I have updated the PR to add support for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks! The trick with forcing the closure to be FnOnce
is quite cool. I just had a couple comments about variable hygiene, then it should be ready to merge
Thanks for the PR! I'll release version 0.2.0 with these changes |
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.