Skip to content

Named impls #2251

@SoniEx2

Description

@SoniEx2

As of right now all impls are anonymous and public. I propose named impls and named public impls:

impl X as Y for Z for a private impl

pub impl X as Y for Z for a public impl

This is similar to how traits currently work: you need to import them to use them.

With a non-pub impl, you can use it within your module. With a pub impl, you can use it outside your module. In any case, you need to explicitly import it with use. You can also import them from an external crate, but it follows the same rules - only available where you use them.

Later we could also add !pub impl Y for Z if we want crate-wide, anonymous impls. (Sadly, since they're already public by default, we can't have impl Y for Z and pub impl Y for Z, except maybe in Rust 2.0.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions