Rust学习笔记 3.3 Tuples 元组

3.3 Tuples 元组

  • 相似类型有数组、切片,但在rust中不常用,常用Vector

元组

  • 匿名存储数据
  • 不可变

元组的用处

  • 函数返回
  • 提取变量

代码

fn a_tuple() -> (i32, i32) {
    
    
    (0, 1)
}

fn main() {
    
    
    println!("{:?}", a_tuple());
    let (a, b) = a_tuple();
    println!("a: {}, b: {}", a, b);
}

猜你喜欢

转载自blog.csdn.net/qq_51173321/article/details/125963021
3.3