{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreiewgf6sxlvim3r2m4rdw2zdizsqyawjh442hukueaxlq5mueuxgv4",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mgbyg4s2ylv2"
},
"path": "/t/f-pattern-types-subsets-enums-using-as/24048#post_20",
"publishedAt": "2026-03-04T10:16:42.000Z",
"site": "https://internals.rust-lang.org",
"tags": [
"Subtyping",
"[1]",
"[2]",
"↩︎"
],
"textContent": "CAD97:\n\n> In any case, pattern restricted types are stalled because they're _difficult_. We want to inherit all functionality from `MyError` to `MyErrorSubset`, but while `&MyErrorSubset ⊆ &MyError`, `&mut MyError ⊆ &mut MyErrorSubSet`, and also `&MyError ⊆ &mut MyError` and `&MyErrorSubset ⊆ &mut MyErrorSubset`, so it's a complicated mess, and internal mutability makes things even more complicated… knowing what associated functions and trait impls can be provided on the subset type is a very thorny problem, and it gets even _more_ thorny once you start considering forwards compatibility with API evolution that we deem semver compatible.\n\nCorrect me if I'm wrong, but isn't Subtyping basically the same problem, just on lifetimes? Without further niche and layout optimizations (that change the memory layout) I do not see much of a difference conceptually (though in the implementation there probably is a very large difference). It could probably be done by using the parent type but adding a subtype_id to it that is used for pattern match exhaustiveness checks. [1]\n\nscottmcm:\n\n> The hard question is whether `Result<T, MyErrorSubset>` can actually be any smaller if it's defined that way.\n\nThat's mostly a question of whether you want to allow getting a `&mut MyError` from a `MyErrorSubset` or `&mut MyErrorSubset`, right? I suspect there is no good answer to that question, as both cases are valid and useful. I don't even know how many of the people (myself included) asking for pattern types want/need which one. [2]\n\n* * *\n\n 1. And in the future perhaps for layout, though that sounds way more complicated. ↩︎\n\n 2. Perhaps needing both options and a way to choose whether you want `&mut Parent` or a smaller memory footprint (e.g. for `u64 is 100_000..100_050`, which could be a u8 and/or have many niches). ↩︎\n\n\n",
"title": "F-pattern_types : Subsets enums using as"
}