I want to be able to say "this trait is a child of that super trait so it should implement all its functions".
The issue is that trait X: Y {} means that Y and X must be implemented. I just want X to be implemented, but making sure all the functions match Y.
trait GeneralA {
fn get_x() -> String;
}
// Issue: cannot do `SpecificA : GeneralA` without also implementing GeneralA, but I want to enforce only having specific implementations, no general or default functions are possible.
trait SpecificA {
fn get_x() -> String;
}
trait SpecificB {
fn get_x() -> String;
}
struct S1;
impl SpecificA for S1 {
fn get_x() -> String {
"SpecificA->get_x".to_string()
}
}
impl SpecificB for S1 {
fn get_x() -> String {
"SpecificB->get_x".to_string()
}
}
fn main() {
dbg!(<S1 as SpecificA>::get_x());
dbg!(<S1 as SpecificB>::get_x());
}
What I want to describe in the type system:
- Structs can implement zero or more
SpecificXtraits. - Structs cannot implement the
GeneralAtrait. - All
SpecificXtraits should have all functions ofGeneralAtrait. - When cast to a trait type, the compiler should error if its not implemented for that struct.
The issue is that Rust expects me to implement GeneralA AND SpecificX.
How can I do this in the type system?