0

I am reading The Rust Programming Language, and I am stuck at trait bound syntax:

pub trait Summary {
    fn summarize(&self) -> String;
}

pub fn notify1(item1: &impl Summary, item2: &impl Summary) {}

pub fn notify2<T: Summary>(item1: &T, item2: &T) {}

We use trait Summary to bound the parameter's type of function notify1 and notify2.

Why do we use impl Summmary in notify1, but use Summary in notify2? I think use Summary in notify1 instead of impl Summary is more natural.

Shepmaster
  • 326,504
  • 69
  • 892
  • 1,159
gaoxinge
  • 439
  • 1
  • 8
  • 20

0 Answers0