Skip to content

ACP: Implement Fn traits for Rc and Arc #143

@nvzqz

Description

@nvzqz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions