I got a codebase where I got lots of complex type parameter constraints. Things like:
fn foo<T>(x: T)
where T: Display + Debug + Send + Sync + Clone + 'static
{}
I find this kind of annoying. So I came up with this way to DRY the constraints:
use std::fmt::{Display, Debug};
trait TheUsual: Display + Debug + Send + Sync + Clone + 'static {}
impl<T: Display + Debug + Send + Sync + Clone + 'static> TheUsual for T {}
fn foo(x: impl TheUsual) {
println!("{} {:?}", x, x);
}
fn main() {
foo(1);
}
This seems to work as far as I can see. Is this a common pattern? What's the downside, other than having to come up with another name?