【发布时间】:2022-10-06 05:49:25
【问题描述】:
在以下代码中:
pub trait Thinger {
fn print_thing(&self) where Self: core::fmt::Debug {
println!("trait method: {:?}", self);
}
}
#[derive(Debug)]
pub struct Thing(f64);
impl Thing {
fn print_thing(&self) where Self: core::fmt::Debug {
println!("method: {:?}", self);
}
}
impl Thinger for Thing {}
fn main() {
let thing = Thing(3.14);
thing.print_thing();
}
如何调用Thinger 的print_thing 方法?
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0717f5615e10e3a1349f6db9cb9c3306
我在 The Book 中看到过,但我在任何地方都找不到。
【问题讨论】:
标签: rust overriding traits