当前位置:网站首页>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]
}
边栏推荐
- Summary of knowledge points of Engineering Economics
- 手把手教你安装VSCode(附带图解步骤)
- Even PostgreSQL problem: expected authentication request from server, but received V
- 即时通讯场景下安全合规的实践和经验
- Responsive dream weaving template makeup website
- Data security and privacy computing summit - development and application of security intersection in privacy Computing: Learning
- Thermistor temperature calculation formula program
- 一文理解分布式开发中的服务治理
- Responsive Zhimeng template decoration design website
- 2022/07/28 learning notes (day18) common APIs
猜你喜欢

Data security and privacy computing summit - development and application of security intersection in privacy Computing: Learning

Redis主从模式、哨兵集群、分片集群

FPGA刷题——存储器(RAM和FIFO的Verilog实现)

响应式织梦模板户外露营类网站
[email protected] The localization rate reaches 100%"/>Quanzhi t3/a40i industrial core board, 4-core [email protected] The localization rate reaches 100%

无线振弦采集系统工作流程

HTTP缓存

Split, an avalanche caused by connection pool parameters

【MQTT从入门到提高系列 | 09】WireShark抓包分析MQTT报文

Remember error scheduler once Asynceventqueue: dropping event from queue shared causes OOM
随机推荐
Rust 列表(Vec)复制
会议OA之会议通知
【MQTT从入门到提高系列 | 09】WireShark抓包分析MQTT报文
Servlet三种实现方式
Kubesphere-多节点安装
“两个披萨”团队的分支管理实践
WebView attack
Awvs cannot start problem
MySQL驱动中关于时间的坑
Even PostgreSQL problem: expected authentication request from server, but received V
一文搞懂 Redis 架构演化之路
Remember error scheduler once Asynceventqueue: dropping event from queue shared causes OOM
Talk about 11 tips for interface performance optimization
Derivation of Euler angle differential equation
Never pass a request to an asynchronous thread. There is a hole
What if there is not enough time for adequate testing?
网络安全漏洞管理的探索与实践
响应式织梦模板酒店客房类网站
How does the Devops team defend against API attacks?
Split, an avalanche caused by connection pool parameters