如何调用默认特征方法?

时间:2015-11-30 15:31:43

标签: rust

struct如何实现特征方法,还可以调用该方法的默认版本?

pub trait MyTrait {
    fn do_it(&self) {
        println!("I am doing it the default way.");
    }
}

pub struct MyStruct;

impl MyTrait for MyStruct {
    fn do_it(&self) {
        println!("Doing it my way.");
        //Call default method
        self.MyTrait::do_it(); //Not worky
    }
}

fn main() {
    let m = MyStruct;

    m.do_it();
}

0 个答案:

没有答案