当前位置:网站首页>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]
}
边栏推荐
- 0728~ sorting out interview questions
- 深度剖析 —— 预处理
- Esbuild Bundler HMR
- 即时通讯场景下安全合规的实践和经验
- Remember error scheduler once Asynceventqueue: dropping event from queue shared causes OOM
- 6年测试经验,教大家测试~如何把控项目
- 连PostgreSQL问题:expected authentication request from server, but received v
- [RT learning note 1] RT thread peripheral routine - control LED light flashing
- 裂开了,一次连接池参数导致的雪崩问题
- 我被这个浏览了 746000 次的问题惊住了
猜你喜欢

Responsive dream weaving template outdoor camping website

结合Retrofit 改造OKHttp 缓存

响应式织梦模板化妆美妆类网站

Day 15 (VLAN related knowledge)

Time pit in MySQL driver

I want to talk about high concurrency.

基于对象的实时空间音频渲染丨Dev for Dev 专栏

What happens if you have to use ArrayList in multithreading?

如果非要在多线程中使用 ArrayList 会发生什么?

C language improvement (I)
随机推荐
高效使用浏览器的5个小技巧,第1个技巧最实用
npm install 报错 Error: EPERM: operation not permitted, rename
如果非要在多线程中使用 ArrayList 会发生什么?
Work queue_ queue
Code random notes_ Hash_ 349 intersection of two numbers
HTTP断点续传以及缓存问题
2022/07/28 learning notes (day18) common APIs
无线振弦采集系统工作流程
WebView attack
[quality] code quality evaluation standard
当Synchronized遇到这玩意儿,有个大坑,要注意
Rust 列表(Vec)复制
What should I do if excel opens a CSV file containing Chinese characters and there is garbled code?
关于高并发,我想聊一聊。
[golang learning notes 2.2] map, structure and interface
Meeting notice of meeting OA
工程经济学简答题
进程间通信---对管道的详细讲解(图文案例讲解)
FPGA skimming memory (Verilog implementation of ram and FIFO)
开启TLS加密的Proftpd安全FTP服务器安装指南