Rust如何调用"父方法"?在Java中是这样的:
public class parent{
...
public void doSomething(){
System.out.println("Parent method");
}
}
public class child extends parent{
...
public void doSomething(){
super.doSomething();
System.out.println("Child method.");
}
}
在Go中,我们可以通过struct中的匿名字段进行模拟:
type parent struct{}
func (self *parent) doSomething() {
fmt.Println("parent method")
}
type child struct {
parent
}
func (self *child) doSomething() {
self.parent.doSomething()
fmt.Println("child method")
}
func main() {
var c1 child
c1.doSomething()
}
如何在Rust中模拟它?谢谢