Both are clones, why is the former possible and the latter not
trait GetName {
fn get_name(&self) -> &String;
}
#[derive(Clone)]
struct Student {
name : String,
}
impl GetName for Student {
fn get_name(&self) -> &String {
&self.name
}
}
fn print(item : impl GetName) {
println!("name = {:?}", item.get_name());
}
fn produce() -> impl GetName {
Student {
name : String::from("shawy"),
}
}
fn main() {
let s = Student {
name : String::from("alice"),
};
print(s.clone()); // Why does it run correctly here ?
let s = produce();
print(s.clone()); // Why is it running incorrectly here ?
}
ERROR:
--> src\main.rs:33:13
| let s = produce();
33 | print(s.clone());
| ^^^^^ method not found in `impl GetName`