当前位置:网站首页>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]
}
边栏推荐
- Responsive dream weaving template hotel room website
- “两个披萨”团队的分支管理实践
- 响应式织梦模板户外露营类网站
- Time pit in MySQL driver
- Responsive dream weaving template makeup website
- 详解JS的四种异步解决方案:回调函数、Promise、Generator、async/await
- Talk about the implementation principle of feign
- 当Synchronized遇到这玩意儿,有个大坑,要注意
- 矿山开采虚拟现实vr安全培训提升员工警惕性和防护意识
- Quanzhi t3/a40i industrial core board, 4-core [email protected] The localization rate reaches 100%
猜你喜欢

Time pit in MySQL driver

What should I do if excel opens a CSV file containing Chinese characters and there is garbled code?

【质量】代码质量评价标准

Prometheus + alertmanager message alert

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

Experiment 2: Arduino's tricolor lamp experiment

Day 14: continued day 13 label related knowledge

Explain asynchronous tasks in detail: task status and lifecycle management

When I look at the source code, what am I thinking?

Responsive dream weaving template outdoor camping website
随机推荐
矿山开采虚拟现实vr安全培训提升员工警惕性和防护意识
多线程浅谈
如果非要在多线程中使用 ArrayList 会发生什么?
TCP重传机制有哪些?
连PostgreSQL问题:expected authentication request from server, but received v
KBxxxxxx不一定是补丁,也可能是某个问题解决方案的描述
After 4 years of testing experience, I finally entered Alibaba. Two months later, I chose to resign naked
Meeting notice of meeting OA
MySQL和Redis的双写一致性
Brief answer of Engineering Economics
7/28 Gauss elimination to solve linear equations + Gauss elimination to solve XOR linear equations + find the combination number II
How much is the report development cost in the application system?
Even PostgreSQL problem: expected authentication request from server, but received V
How awesome is the architecture of "12306"?
3d智能工厂工艺流转可视化交互展示应用优点
聊聊接口性能优化的11个小技巧
I was stunned by this question that I browsed 746000 times
Data security and privacy computing summit - development and application of security intersection in privacy Computing: Learning
7/28 高斯消元解线性方程组+高斯消元解异或线性方程组 +求组合数ii
HTTP断点续传以及缓存问题