day 36 @rust trait①

・traitの定義とtraitの実装方法

trait MyTrait {
    fn shared_function(&self);
}

impl MyTrait for MyStruct {
    fn shared_function(&self) {
        // do something
    }
}

・メソッドのデフォルト動作を決めておく

trait MyTrait {
    fn shared_function(&self) {
        println!("hello the world!!")
    }
}

impl MyTrait for MyStruct { }

・メソッドのオーバーライドは可能だが、デフォルト時の実装の再利用はできない。
C#でいうbase.method()はできない。