当前位置:网站首页>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]
}
边栏推荐
- How awesome is the architecture of "12306"?
- Kbxxxxx is not necessarily a patch, but also a description of a solution to a problem
- Polygon point test
- After 4 years of testing experience, I finally entered Alibaba. Two months later, I chose to resign naked
- Rust 列表(Vec)复制
- 响应式织梦模板家装建材类网站
- 代码实现 —— 多项式的最大公因式(线性代数)
- Exploration and practice of network security vulnerability management
- 开启TLS加密的Proftpd安全FTP服务器安装指南
- 手把手教你安装VSCode(附带图解步骤)
猜你喜欢

Prometheus + AlertManager 消息预警
[email protected] The localization rate reaches 100%"/>Quanzhi t3/a40i industrial core board, 4-core [email protected] The localization rate reaches 100%

Esbuild Bundler HMR

C language improvement (I)

2022/07/28 学习笔记 (day18) 常用API

防止勒索软件攻击数据的十种方法

On Multithreading

响应式织梦模板酒店客房类网站

Installation guide for proftpd Secure FTP server with TLS encryption enabled

详解异步任务:任务的状态及生命周期管理
随机推荐
7/28 Gauss elimination to solve linear equations + Gauss elimination to solve XOR linear equations + find the combination number II
What happens if you have to use ArrayList in multithreading?
HTTP断点续传以及缓存问题
Transform okhttp cache with retrofit
Work queue_ queue
聊聊接口性能优化的11个小技巧
一文理解分布式开发中的服务治理
防止勒索软件攻击数据的十种方法
Waiting queue wait_ queue
fopen、_ Wfopen reads Unicode encoded files
Never pass a request to an asynchronous thread. There is a hole
Explain the four asynchronous solutions of JS in detail: callback function, promise, generator, async/await
C language improvement (I)
3D模型格式全解|含RVT、3DS、DWG、FBX、IFC、OSGB、OBJ等70余种
【上传图片可剪裁-1】
Experiment 2: Arduino's tricolor lamp experiment
ES6详解 快速上手!
Summary of knowledge points of Engineering Economics
ES6 event binding (v-on usage)
开启TLS加密的Proftpd安全FTP服务器安装指南