ZhangHanDong / tao-of-rust-codes

《Rust编程之道》随书源码
https://ruststudy.github.io/tao_of_rust_docs/tao_of_rust/
MIT License
1.18k stars 170 forks source link

2.10.2 节 动态分发写法在新版本中已经废弃 #325

Open lvheyang opened 3 years ago

lvheyang commented 3 years ago

页码与行数


代码错误

fn fly_dyn(s: &Fly) -> bool {  // 此处根据新版本的rust,应该改为 (s: &dyn Fly)
    s.fly()
}

Rust版本

$ rustc -V
rustc 1.53.0 (53cb7b09b 2021-06-17)

错误信息

warning: trait objects without an explicit `dyn` are deprecated
  --> src/main.rs:20:16
   |
20 | fn fly_dyn(s: &Fly) -> bool {
   |                ^^^ help: use `dyn`: `dyn Fly`
   |
   = note: `#[warn(bare_trait_objects)]` on by default

warning: 1 warning emitted

可以考虑在书中注明不同版本的写法

ZhangHanDong commented 3 years ago

感谢反馈。 这个写法只能在第二版里改了。