Alias for trait bounds

So for structs and traits we have type A = B which defines an alias A for B, which is similar to C's typedef. I was wondering if there is some equivalent to this for trait bounds. E.g. imagine I have 10-15 methods all having the same bound:
i64: From<C>, C: Clone + Mul<i64> + Add<i64> + Neg<i64> .... is there any way to define an alias for this trait bound such that I can make my function definitions not spawn on several lines and the code to be more readable?

1 Like

There's an open RFC to do this: https://github.com/rust-lang/rfcs/pull/1733

You can also define a trait that requires all of them and a blanket impl:

trait Foo: Clone + Mul<i64> + Add<i64> + ... {}

impl<T> Foo for T where T: Clone + Mul<i64> + Add<i64> + ... {}

fn foo<C>() where i64: From<C>, C: Foo {}
4 Likes

Thanks that will make it clearer I guess.