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
jer
April 19, 2019, 3:24pm
3
It’s kinda possible on Nightly since forever using auto traits, see this little playground example
4 Likes
@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: https://github.com/rust-lang/rust/issues/20041
1 Like
system
Closed
July 18, 2019, 4:35pm
6
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.