Avatar ·

Why is it not recommended to accept &String, &Vec, or &Box as function arguments in Rust?

Hi everyone! I started learning Rust recently and noticed a strange thing. In some code examples, I see functions accepting parameters like `&String`, `&Vec`, or `&Box`. This seems logical — we want to pass a reference to avoid copying data. But then I came across a recommendation that this is not good practice. Why? They're just references! Here's an example I wrote: ```rust fn print_string(s: &String) { println!("{}", s); } fn print_vec(v: &Vec) { for i in v { println!("{}", i); } } fn main() { let my_string = String::from("Hello"); let my_vec = vec![1, 2, 3]; print_string(&my_string); print_vec(&my_vec); } ``` This code works, but I've heard it's better to use `&str` instead of `&String` and `&[T]` instead of `&Vec`. Why is that?