Define an alias type/trait within a Struct


#1

I have a generic struct and its implementations uses many times the following callable signature Fn(&SomeType, &SomeOtherType, &T) -> MyResult as argument type in different functions (T is the generic Type). I would like to provide an alias for this, not only to avoid typing but also to avoid errors. But the alias needs to be defined inside the struct. Is there a way to do this?


#2

This is not possible inside the struct, but it’s possible outside:

type MyFn<T>=Fn(&SomeType, &SomeOtherType, &T) -> MyResult;

#3

Thanks for the response. It is not optimal but it is better than my current solution. I tried this in past but I was getting:

error: expected a reference to a trait [E0172]