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

Relax memctx closures from Fn to FnOnce #390

Merged
merged 1 commit into from
Jan 21, 2022

Conversation

Hoverbear
Copy link
Contributor

@Hoverbear Hoverbear commented Jan 20, 2022

While working on #230 I was trying to use pgx::memcxt::PgMemoryContexts::exec_in_context and pgx::memcxt::PgMemoryContexts::switch_to and realized they used Fn over FnOnce.

This means that closures using it:

let internal = String::default();
PgMemoryContexts::TopTransactionContext.switch_to(|context| {
    let path = Path::from(internal); // <-- `internal` must be moved here by value, not ref.
});

Would get errors like: "cannot move out of internal, a captured variable in an Fn closure`"

This should not break anything for users, as it's a general relaxation.

Notably:

Since both Fn and FnMut are subtraits of FnOnce, any instance of Fn or FnMut can be used where a FnOnce is expected.

@Hoverbear Hoverbear self-assigned this Jan 20, 2022
@eeeebbbbrrrr
Copy link
Contributor

LGTM. Feel free to merge.

@Hoverbear Hoverbear merged commit de8ce98 into develop Jan 21, 2022
@Hoverbear Hoverbear deleted the memctx-closure-relaxation branch January 21, 2022 05:24
@Hoverbear Hoverbear mentioned this pull request Feb 9, 2022
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