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

Allow indirect/partially owned mapping #408

Open
ilyvion opened this issue Oct 16, 2023 · 1 comment
Open

Allow indirect/partially owned mapping #408

ilyvion opened this issue Oct 16, 2023 · 1 comment

Comments

@ilyvion
Copy link

ilyvion commented Oct 16, 2023

I don't know if the title is all that self-explanatory, but it's the best I could think of, so let me instead try to explain what I mean here:

Today, RwLockReadGuard takes a closure with the signature FnOnce(&T) -> &U, which means that the only thing you can do is return a borrowed value. This means you can't do something like

struct MyCustomType<'a> {
    value: &'a Value,
}
// used with `map` like:
RwLockReadGuard::map(guard, |value| MyCustomType {
    value,
})

since, although this is still a sensible mapping, it does not fit the shape of a &U and will be rejected.

@Amanieu
Copy link
Owner

Amanieu commented Oct 17, 2023

This was previously raised in #289/#290. Basically, the issue is that Rust's lifetime system can't properly support this at the moment.

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

No branches or pull requests

2 participants