当前位置:网站首页>Rust list (VEC) replication
Rust list (VEC) replication
2022-07-29 02:32:00 【liberg】
Rust in Vec List the type Realized clone(), You can directly call and copy a new list .
#[test]
fn test_list_clone() {
// Construct a list :[5,4,3,2,1]
let list = (1..=5).rev().collect::<Vec<_>>();
// Method 1 : adopt clone() Copy list
let mut list_sorted = list.clone();
list_sorted.sort_unstable();
// Method 2 : New list , Then add / Set the element
let mut list_new = vec![0; list.len()];
list.iter().enumerate().for_each(|(i,e)| {
list_new[i] = *e;
});
list_new[2] = 300;
// Copy the 2 A new one , Can be modified separately , They don't influence each other
println!("{:?}", list);//[5, 4, 3, 2, 1]
println!("{:?}", list_sorted);//[1, 2, 3, 4, 5]
println!("{:?}", list_new);//[5, 4, 300, 2, 1]
}
边栏推荐
- 工程经济学名词解释
- Brief answer of Engineering Economics
- Code implementation - the greatest common factor of polynomials (linear algebra)
- 密码安全如何保障?安全浏览器如何管理密码?
- ES2022 的 8 个实用的新功能
- 无线振弦采集系统工作流程
- 手把手教你安装VSCode(附带图解步骤)
- Experiment 2: Arduino's tricolor lamp experiment
- Talk about the implementation principle of feign
- DevOps 团队如何抵御 API 攻击?
猜你喜欢

即时通讯场景下安全合规的实践和经验

Remember error scheduler once Asynceventqueue: dropping event from queue shared causes OOM

响应式织梦模板家装装饰类网站

一文搞懂 Redis 架构演化之路

Time pit in MySQL driver

3d智能工厂工艺流转可视化交互展示应用优点

线上3d数字展厅制作方案及优点

当Synchronized遇到这玩意儿,有个大坑,要注意

C language improvement (I)

How to guarantee password security? How does the secure browser manage passwords?
随机推荐
快速掌握Nodejs安装以及入门
Responsive dream weaving template makeup website
PS + PL heterogeneous multicore case development manual for Ti C6000 tms320c6678 DSP + zynq-7045 (2)
响应式织梦模板酒店客房类网站
Awvs cannot start problem
Explain asynchronous tasks in detail: task status and lifecycle management
会议OA之会议通知
3d智能工厂工艺流转可视化交互展示应用优点
3D模型格式全解|含RVT、3DS、DWG、FBX、IFC、OSGB、OBJ等70余种
FPGA刷题——存储器(RAM和FIFO的Verilog实现)
Explanation of engineering economics terms
连PostgreSQL问题:expected authentication request from server, but received v
QT qstackedwidget multi interface switching
深度剖析 —— 预处理
Never pass a request to an asynchronous thread. There is a hole
响应式织梦模板户外露营类网站
高效使用浏览器的5个小技巧,第1个技巧最实用
How much is the report development cost in the application system?
ES6详解 快速上手!
On Multithreading