Extending Traits

Rust has trait inheritance, it looks like this:

pub trait A {}
pub trait B: A {}

However, this does not mean that if a type extends B it will automatically extends A; trait inheritance is just a way to specify requirements, that is, trait B: A means that we can know that if some type T implements B, it also necessarily implements A.

Naturally, you can use this to specify that a trait extends a combination of other traits:

pub trait Something: Clone + Send + WhateverOtherTrait {}

Again, it just means that every type which implements Something must also implement Clone, Send and WhateverOtherTrait.

Implementing multiple traits at the same time is not possible. I think this is because in the vast majority of situations traits are sufficiently different so such implementation won't work anyway.

11 Likes