Reverse generic traits specification

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?

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.

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

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

1 Like

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.

1 Like