Reverse generic traits specification


#1

So rather than the standard where T: D I need something like T where i64::From<T> is implemented. How can I make this specification in rust?


#2

T: Into<i64> is strictly more general than i64: From<T>, so it’s usually better to use that.

You can write:

fn f<T>(t: T) where i64: From<T> { ... }

if you really want to.


#3

Oh damn, did not realize after the where clause you don’t need to specifically have T:. thanks


#4

The where clause is a comma separated list, so you could have both T: conditions and other related conditions.


#5

The where clause is a comma-separated list of type: bound pairs. The type can be anything from a type parameter like T, a concrete type like i64, a type parameterized by T like Vec<T> or (very commonly) an associated type, for example: where T: Iterator, T::Item: Display.