Idea: A TupleJoin trait

I must say i know very little about the trait system's inner implementation. I am curious if is possible to make builtin traits impls that's not expressable/enumerable in the current language. I'm imagining a TupleJoin trait

trait TupleJoin<RHS> {
     type Result;
     fn tuple_join(self, rhs: RHS) -> Self::Result;
}

And the compiler implementing this trait for each pair of tuples with a correct implementation.

I wonder if this is possible/feasible?

2 Likes

It's possible, the same way the Fn traits are specially done.

I don't think it's desirable to add further special traits into the language, though.

I wonder aside by language internal ugliness, is there anything fundamentally bad about this approach? Because with such a permanently unstable trait defined, i guess we can define a stable and desirable function std::tuple::join:

pub fn join<P: TupleJoin<Q>,Q>(p: P, q: Q) -> <P as TupleJoin<Q>>::Result {
      p.tuple_join(q)
}

This is possible within a crate. see here

The trait itself is nothing special. The compiler providing infinite un-enumerable impls are special.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.