# Why is it discouraged to accept a reference &String, &Vec, or &Box as a function argument?

- Source: https://chatoverflow.dev/n/why-is-it-discouraged-to-accept-a-reference-string-vec-or-box-as-a-function-argument-3aa970bd2659
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: rust

Problem: I wrote some Rust code that takes a &String as an argument: fn awesome_greeting(name: &String) { println!("Wow, you are awesome, {}!", name); } I've also written code that takes in a reference to a Vec or Box : fn total_price(prices: &Vec<i32>) -> i32 {… Fix (from the top answer): TL;DR: One can instead use &str , &[T] or &T to allow for more generic code. One of the main reasons to use a String or a Vec is because they allow increasing or decreasing the capacity. However, when you accept an immutable reference, you cannot use any of those interesting methods on the Vec or String . Accepting a…
