t_wの輪郭

Feedlyでフォローするボタン
Rust特質implfntrait特質を型に実装するforimpl for
trait Summary {
    fn summarize(&self) -> String {
        String::from("(Read more...)")
    }
}

struct NewsArticle {
    pub headline: String,
    pub location: String,
    pub author: String,
    pub content: String,
}

impl Summary for NewsArticle {}

fn main() {
    let news_article = NewsArticle{
        headline: String::from("Headline"), 
        location: String::from("somewhere"), 
        author: String::from("somebody"), 
        content: String::from("something")
    };

    println!("{}", news_article.summarize());
}

https://doc.rust-jp.rs/book-ja/ch10-02-traits.html#デフォルト実装

あれ