【rust】vec

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;
}

 

posted @ 2021-01-17 21:58  carrotmvp  阅读(252)  评论(0编辑  收藏  举报