Maybe it’s a over-use of the inference engine, but i wonder if it is feasible to add a “boolean” where clause item. I imagine it would use some same mechanism from const generics.

Example code:

struct S<T,U>;
impl<T, U> S<T,U> where const TypeId::of::<T> == TypeId::of::<U> {
     fn some_method() {
1 Like

In this particular example, you could impl<T> S<T, T>. Trying to match T != U would be new though.

1 Like

It’s kinda possible on Nightly since forever using auto traits, see this little playground example


@jer Interesting! I never learnt this before.

I’m adding more examples:

//ignore missing #[fundamental] here.
impl<T, const N: usize> [T; N]  {
    fn prefix<const M: usize>(&self) -> [T; M] 
        where T: Clone, const M <= N {

If all you want are type equality constraints, then take a look at this tracking issue:

1 Like

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