[−][src]Function tao_of_rust::ch06::functions::mut_params
pub fn mut_params()
函数:参数传递
Base usage: 可变参数按值传递
fn modify(mut v: Vec<u32>) -> Vec<u32> { v.push(42); v } fn main(){ let v = vec![1,2,3]; let v = modify(v); println!("{:?}", v); }Run
Base usage: 可变参数传递按引用传递
fn modify(v: &mut [u32]) { v.reverse(); } fn main(){ let mut v = vec![1,2,3]; modify(&mut v); println!("{:?}", v); // [3, 2, 1] }Run