< 返回我的博客

beckbikang 发表于 2022-06-27 22:14

Tags:基本类型

fn main() {
    //基本类型
    let a :i32 = 12;
    let a1 :i32 = 0x1a;
    let a2 :f32 = 12.3;
    let b1 :bool = true;
    let ch1 = "中国";
    println!("{} {} {} {} {}",a,a1, a2, b1, ch1);

    //元组
    let tup1 = (1,2,3);
    println!("{} ", tup1.0);

    //指针
    let tup2 = (21,"tom");
    let box1 = Box::new(tup2);
    println!("box1:{} ", box1.0);

    //数组,向量和切片
    let mut arr1:[u32;3] = [2,3,1];
    println!("arr1:{}",arr1[0]);
    arr1.sort();
    println!("arr1:{}",arr1[0]);

    let mut vec1 = vec![2,3,5,7];
    vec1[1] = 123;
    println!("vec1:{}",vec1[1]);

    let vec2:Vec<i32> = (0..5).collect();
    println!("vec2:{}",vec2[1]);
    let vec22 =  &vec2[0..1];
    println!("vec22[1]={}",vec22[0]);

    let mut vec3 = Vec::with_capacity(3);
    vec3.push(11);
    vec3.push(12);
    vec3.push(13);
    vec3.remove(1);
    println!("vec3:{}",vec3[1]);


    //字符串
    let speech = "said the well\n";
    println!("{}", speech);
    let method = b"GET";
    //println!("{}", method);

}

评论区

写评论

还没有评论

1 共 0 条评论, 1 页