What Is the Difference Between Traits in Rust and Interfaces in Java/Go?

Rust traits define shared behavior like interfaces but uniquely allow default method implementations and associated types.

Rust traits define shared behavior for types but differ from Java/Go interfaces by allowing default method implementations and supporting associated types. While Java and Go interfaces are purely abstract contracts, Rust traits can provide concrete logic that implementing types inherit or override.

trait Summary {
    fn summarize(&self) -> String;
    fn summary_author(&self) -> String { "Anonymous".to_string() }
}

struct NewsArticle {
    headline: String,
}

impl Summary for NewsArticle {
    fn summarize(&self) -> String {
        format!("Read more: {}", self.headline)
    }
}