How does trait inheritance work

Rust replaces trait inheritance with trait objects and default method implementations to share behavior across types.

Rust does not support trait inheritance; instead, it uses trait objects and default implementations to share behavior. You define a trait with shared methods and implement it on multiple structs, optionally providing default logic in the trait itself.

trait Draw {
    fn draw(&self) {
        println!("Drawing default shape");
    }
}

struct Button;
impl Draw for Button {}

struct Image;
impl Draw for Image {
    fn draw(&self) {
        println!("Drawing image");
    }
}