HiveBrain v1.2.0
Get Started
← Back to all entries
patternrustCritical

Is there a way to combine multiple traits in order to define a new trait?

Submitted by: @import:stackoverflow-api··
0
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++:

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.