为什么不允许引用字符串(&String)、Vec(&Vec)或Box(&Box)作为函数参数?
&String
fn awesome_greeting(name: &String) {
println!("Wow, you are awesome, {}!", name);}VecBox:
fn total_price(prices: &Vec<i32>) -> i32 {
prices.iter().sum()}fn is_even(value: &Box<i32>) -> bool {
**value % 2 == 0}
温温酱
皈依舞
随时随地看视频慕课网APP