For example, I want to write the trait for containers in Rust:
trait Container: Default {
type ValueType;
}
But also I want that all Containers also can be Cloned only when Container::ValueType can be Cloned:
// not Rust code
trait Container: Default + Clone if Self::ValueType: Clone {
type ValueType;
}
Of course, I could conditionally implement Clone trait for the concrete container itself:
struct MyVec<T> {}
impl<T: Clone> Clone for MyVec<T> {/**/}
or use derive(Clone), but I want to express my intention for Container trait, not for implementing types.