I am trying to understand generics in Rust. I am not able to get what went wrong here
fn say<T>(msg: &T) {
let slen = msg.chars().count();
if slen > 0 {
println!("Char Count {} " ,slen);
}
}
fn main() {
let msg = String::from("Hello World from Rust!!!");
say::<String>(&msg);
}
Compilation Error:
error[E0599]: no method named `chars` found for reference `&T` in the current scope
--> hell.rs:4:20
|
4 | let slen = msg.chars().count();
| ^^^^^ method not found in `&T`