Skip to content

Unimplementable ("Sealed") Traits #2822

@elichai

Description

@elichai

Hi,
a lot of times you want to have a trait in your library/crate that can't be implemented by the library users.
either because it's a marker trait for FFI related things, related to a custom type system, or because it's very highly unsafe and weird.

libstd's solution to this problem is exposing pub traits but marking them unstable to implement i.e. https://doc.rust-lang.org/std/slice/trait.SliceIndex.html

I propose we add something like #[non_exhaustive] but for traits, i.e. #[unimplementable]
we can already see similiar weird tricks in the wild, i.e.
https://docs.rs/zerocopy/0.2.8/src/zerocopy/lib.rs.html#207
https://github.com/rust-bitcoin/rust-secp256k1/blob/master/src/context.rs#L10
and more.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-privacyPrivacy related proposals & ideasA-traitsTrait system related proposals & ideasT-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