[初学rust] 06_rust 元组

rust 元组

表现形式

和python的元组类似,rust中的元组是一个有序列表,可以包含多种不同类型的数据。

rust 复制代码
let tup = (500, 6.4, 'a');

模式匹配解构元组

和python中的解构一样,rust也支持模式匹配解构元组,但是需要注意的是,如果元组中有多个相同类型的变量,那么必须使用_来跳过。

rust 复制代码
let tup = (500, 6.4, 'a');
let (x, y, _) = tup;
println!("The value of x is: {}", x);
println!("The value of y is: {}", y);

访问元组

这个就和C++的tuple类似,通过点号来访问。

rust 复制代码
let tup = (500, 6.4, 'a');
println!("The value of the tuple is: {}", tup);
println!("The value of the first element in the tuple is: {}", tup.0);
println!("The value of the second element in the tuple is: {}", tup.1);
相关推荐
想回家的一天4 小时前
ECONNREFUSED ::1:8000 前端代理问题
开发语言
cike_y4 小时前
Mybatis之解析配置优化
java·开发语言·tomcat·mybatis·安全开发
WanderInk4 小时前
刷新后点赞全变 0?别急着怪 Redis,这八成是 Long 被 JavaScript 偷偷“改号”了(一次线上复盘)
后端
Jay_Franklin5 小时前
SRIM通过python计算dap
开发语言·python
Slow菜鸟5 小时前
Java基础架构设计(三)| 通用响应与异常处理(分布式应用通用方案)
java·开发语言
吴佳浩5 小时前
Python入门指南(七) - YOLO检测API进阶实战
人工智能·后端·python
消失的旧时光-19435 小时前
401 自动刷新 Token 的完整架构设计(Dio 实战版)
开发语言·前端·javascript
wadesir5 小时前
Rust中的条件变量详解(使用Condvar的wait方法实现线程同步)
开发语言·算法·rust
tap.AI5 小时前
RAG系列(二)数据准备与向量索引
开发语言·人工智能
廋到被风吹走6 小时前
【Spring】常用注解分类整理
java·后端·spring