I have this code:
fn func<T, U>(f: T) where T: Fn()-> U, U: MyTrait {
let state = f();
// ...
}
f here is just a new function from a trait MyTrait for some struct. I want to have a function which works with every struct implementing MyTrait, and there is new method for that trait I want to call for state.
How can I pass the struct (not a value with type of that struct) into a function with restriction on the specific trait been implemented for that struct?
new()that you want to call in yourfun()?fn func<T: MyTrait>(arg: T){let state = T::new();}arg: Tis a function here, and I want to pass the type to use.