I have a struct with a generic type that needs to implement a lot of traits, and it's making my code very frustrating to read/write because I need to include those constraints in so many places. Here is an example:
use std::fmt::*;
use std::ops::*;
pub struct MyStruct<T: Copy + Clone + Display + Debug + Neg + Eq + Ord + Cmp> {
//...
}
impl<T: Copy + Clone + Display + Debug + Neg + Eq + Ord + Cmp> MyStruct<T> {
//...
}
impl<T: Copy + Clone + Display + Debug + Neg + Eq + Ord + Cmp> Ord for MyStruct<T> {
//...
}
impl<T: Copy + Clone + Display + Debug + Neg + Eq + Ord + Cmp> Neg for MyStruct<T> {
//...
}
I haven't tried to compile this example so I may have made mistakes in it, but I think it adequately demonstrates the problem. Is there a way to write this in a way where the type constraints only appear in one place?