{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreihwzyhljx72cd2o6i5whjmbifv274ckzibmwfk2ge2v3oi4gi4jyi",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mnrk2xsoqml2"
},
"path": "/t/named-impl-with-implementation-selection-variant/24374#post_5",
"publishedAt": "2026-06-08T10:39:02.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "Your last example could just forbid the cast from `SortedList<(i32, i32)>` to `SortedList<(i32, i32) + PartialOrd use SortBy1>` and not the named implementation `SortBy1` itself. After all, `PartialOrd` and `PartialOrd use SortBy1` are different traits in a single namespace, which happen to share one interface.\n\nThat makes me think that for the first half no compiler changes are needed at all: just make your traits generic. Using it ergonomically (i.e. type aliases) is another problem, though, and should depend on current codebase patterns.\n\n\n pub enum StandardDef {}\n pub enum RevStandardDef {}\n\n pub trait PartialOrd<Rhs=Self, OrderingKind=StandardDef> {\n fn partial_cmp(self, rhs: Rhs) -> Option<Ordering>;\n }\n\n impl<Lhs, Rhs> PartialOrd<Lhs, RevStandardDef> for Rhs\n where\n Lhs: PartialOrd<Rhs, StandardDef>\n {\n fn partial_cmp(self, other: Lhs) -> Option<Ordering> {\n <Lhs as PartialOrd<Rhs, StandardDef>>::partial_cmp(other, self)\n }\n }\n\n // Or another implementation option doing approximately the same:\n /*\n impl<Lhs, Rhs> PartialOrd<Rhs, RevStandardDef> for Lhs\n where\n Lhs: PartialOrd<Rhs, StandardDef>\n {\n fn partial_cmp(self, rhs: Rhs) -> Option<Ordering> {\n <Lhs as PartialOrd<Rhs, StandardDef>>::partial_cmp(self, other)\n .map(|order| order.flip())\n }\n }\n */\n",
"title": "Named impl with Implementation Selection Variant"
}