Hacker News new | ask | show | jobs
by mamcx 2369 days ago
I like the IDEA but the implementation is not the good one.

Instead, this is what will be elegant:

    pub enum SearchOption {
        Left,
        Full,
    }

    pub enum SearchOptionBeta:SearchOption {
        Rigth,
    }
Yep, extending struct and enums.

This mean MATCH touch "SearchOption" as the "stable" API and the inner crate touch SearchOptionBeta. When SearchOptionBeta need magic is that it match SearchOption too. Later is just a matter of replace one for the other.

And this is even useful for more than to stabilize certain fields or arms...

1 comments

I'd personally do this:

  pub enum SearchOption {
      Left,
      Full,
      Beta(SearchOptionBeta),
  }

  #[non_exhaustive]
  pub enum SearchOptionBeta {
      Right
  }
Yeah, this is how could be done with this, but also show why is a poor abstraction.

If enums were abled to be extended:

  match e: SearchOptionBeta {
   SearchOptionBeta:: Left, Rigth, Full
  }