Inherited traits

We already saw these traits in our trait_inheritance.rs code example. Unlike types in Rust, traits can have an inheritance relationship, for instance:

trait Bar {
fn bar();
}

trait Foo: Bar {
fn foo();
}

In the preceding snippet , we declared a trait, Foo, that depends on a super trait, Bar. The definition of Foo mandates implementing Bar whenever you are implementing Foo for your type. One such example from the standard library is the Copy trait, which requires  the type to also implement the Clone trait.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset