Niektóre metody cech mają domyślne implementacje, które można zastąpić przez implementatora. Jak mogę użyć domyślnej implementacji dla struktury, która nadpisuje wartość domyślną?Używanie metody domyślnej domyślnej
przykład:
trait SomeTrait {
fn get_num(self) -> uint;
fn add_to_num(self) -> uint {
self.get_num() + 1
}
}
struct SomeStruct;
impl SomeTrait for SomeStruct {
fn get_num(self) -> uint { 3 }
fn add_to_num(self) -> uint {
self.get_num() + 2
}
}
fn main() {
let the_struct = SomeStruct;
println!("{}", the_struct.add_to_num()): // how can I get this to print 4 instead of 5?
}