Questions tagged «borrowing»

2
为什么不鼓励接受对字符串(&String),Vec(&Vec)或Box(&Box)的引用作为函数参数?
我写了一些以a &String作为参数的Rust代码: fn awesome_greeting(name: &String) { println!("Wow, you are awesome, {}!", name); } 我还编写了引用Vec或的代码Box: fn total_price(prices: &Vec<i32>) -> i32 { prices.iter().sum() } fn is_even(value: &Box<i32>) -> bool { **value % 2 == 0 } 但是,我收到一些反馈,认为这样做不是一个好主意。为什么不?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.