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

ACP: Implement Fn traits for Rc and Arc #143

Closed
nvzqz opened this issue Dec 7, 2022 · 6 comments
Closed

ACP: Implement Fn traits for Rc and Arc #143

nvzqz opened this issue Dec 7, 2022 · 6 comments
Labels
api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api

Comments

@nvzqz
Copy link

nvzqz commented Dec 7, 2022

Proposal

Problem statement

It is not possible to pass reference-counted closures to APIs that take Fn + 'static or Fn + Clone.

Motivation, use-cases

Many server APIs expect 'static lifetimes but some logic may be implemented in a single closure that's reused in other places. Currently this would require moving captured values and invoking Clone on the closure itself, which clones captured values.

Solution sketches

impl<A, F: Fn<A> + ?Sized> Fn<A> for Rc<F>
impl<A, F: Fn<A> + ?Sized> FnMut<A> for Rc<F>
impl<A, F: Fn<A> + ?Sized> FnOnce<A> for Rc<F>

impl<A, F: Fn<A> + ?Sized> Fn<A> for Arc<F>
impl<A, F: Fn<A> + ?Sized> FnMut<A> for Arc<F>
impl<A, F: Fn<A> + ?Sized> FnOnce<A> for Arc<F>

Alternative solutions: none.

Links and related work

Implementation: rust-lang/rust#105414

What happens now?

This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.

@nvzqz nvzqz added api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api labels Dec 7, 2022
@nvzqz nvzqz changed the title Implement Fn traits for Rc and Arc ACP: Implement Fn traits for Rc and Arc Dec 7, 2022
@nvzqz
Copy link
Author

nvzqz commented Dec 7, 2022

It seems this may be a breaking change without specialization https://github.com/rust-lang/rust/actions/runs/3636798670/jobs/6137112313#step:26:606. 😞

@marmeladema
Copy link

Already requested and rejected at least twice in the past:

@nvzqz
Copy link
Author

nvzqz commented Dec 7, 2022

Thanks for the links. I guess we can add this to the Rust 2.0 bucket list.

@nvzqz nvzqz closed this as completed Dec 7, 2022
@marmeladema
Copy link

To be fair, the ACP process did not exist at the time. Maybe it's a good place to start gathering legitimate use cases and potential breaking concerns? There are some but scattered in the different PRs.
It seems to me that if different people regularly need this, it's a change that should at least be considered by the libs-team and maybe shipped in edition 2024?

@nvzqz
Copy link
Author

nvzqz commented Dec 7, 2022

I don't see how an edition change can fix this unless specialization is stabilized and made automatic.

@marmeladema
Copy link

I think the others attempts were not facing issues with specialization but rather with #[fundamental].
I personally think it's up to the libs-team to give an answer whether such a change is worth introducing in the next edition.

@dtolnay dtolnay closed this as not planned Won't fix, can't repro, duplicate, stale Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api
Projects
None yet
Development

No branches or pull requests

3 participants