Skip to content

Select trait exposes private types #8422

Description

@brson

The Select trait - a public interface - uses the following pattern to hide private implementation details:

priv trait SelectInner { ... implementation details ... }

pub trait Select: SelectInner { ... public API ... }

This is the only place where we use this pattern and I think it's kind of dubious - Select's signature refers to a type that, from the user's perspective, doesn't exist. It's a leaky abstraction.

There may be similar patterns that are more palatable but uses a private enum variant - the enum type is public but opaque.

Activity

  1. bblum commented on Aug 9, 2013

    @bblum
    Contributor

    I both agree and disagree. On the one hand, I'm not particularly proud of it; it was just the only way I could think of to hide the internal types in SelectInner's functions. Suggestions for other ways to do it welcome.

    On the other hand, I see it less as "select uses a type that doesn't exist", and more as "Select is an opaque trait, that is somehow/magically implemented by X, Y, and Z types of ports, which are the only things select() can be used on."

  2. glaebhoerl commented on Aug 9, 2013

    @glaebhoerl
    Contributor

    FWIW Haskell does this a lot so you're in good company. I agree it's not super nice. I don't know what a cleaner way could be. (Exposing the trait and hiding the methods maybe, but that didn't generate too much enthusiasm last time I mentioned it.)

  3. alexcrichton commented on Dec 18, 2013

    @alexcrichton
    Member

    No longer a problem after #10830

  4. added a commit that references this issue on Jul 11, 2021
  5. added a commit that references this issue on Jul 11, 2021
  6. added a commit that references this issue on Mar 14, 2022
  7. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions