patternrustCritical
Is there a way to combine multiple traits in order to define a new trait?
Viewed 0 times
combinenewtraitmultiplewayorderdefinetraitsthere
Problem
Is there a way to combine multiple traits (by inheritance?) in order to define a new trait? I'm looking for something like concepts in C++:
Suppose I want to make a new trait that inherits from
auto concept newConcept : concept1, concept2, concept3 {};
Suppose I want to make a new trait that inherits from
Clone, Default and some other traits, is that possible?Solution
Yep!
trait NewTrait: Clone + Default + OtherTraits {}
impl NewTrait for T where T: Clone + Default + OtherTraits {}
Context
Stack Overflow Q#26983355, score: 103
Revisions (0)
No revisions yet.