let v: Vec<u8>: v = Vec::new(); let v = vec![1,2,3,4];//注意小写v v.push(1); let third: &i32 = &v[2];//访问越界,panic v.get(2);//注意空情况,一般用match for i in &v { println!("{}",i); } for i in &mut v { *i += 100; }
2024-03-28 22:26:16
let v: Vec<u8>: v = Vec::new(); let v = vec![1,2,3,4];//注意小写v v.push(1); let third: &i32 = &v[2];//访问越界,panic v.get(2);//注意空情况,一般用match for i in &v { println!("{}",i); } for i in &mut v { *i += 100; }