Creating a unique set of types in tuple

⚓ Rust    📅 2025-07-25    👤 surdeus    👁️ 2      

surdeus

Hi,
i'm trying to create a unique set of types for example of a Tuple:
e.g.
(usize,usize,usize)-> usize
(usize,u64,usize)-> (usize,u64)
As a starting point a i tried:

pub trait UniqueType {
    type ReducedType;
}

impl<A, B> UniqueType for (A, B)
{
    type ReducedType = Self;
}
impl<A> UniqueType for (A, A)
{
    type ReducedType = A;
}

which doesn't compile due to overlap.
for guarding the different implementations i tried all kinds of unstable features like const expr by making the trait generic over a bool and checking for identical type ids, auto traits with negative impl - they don't work for generic types, specialisation(doesn't work well with associated types) a.s.o but even with these features i couldn't produce a working version even for the must simple case above.
Any hint would be highly appreciated.

1 post - 1 participant

Read full topic

🏷️ Rust_feed