mirror of https://github.com/sunface/rust-course
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
614 B
16 lines
614 B
|
4 years ago
|
# 持久化单向链表
|
||
|
|
迄今为止,我们已经掌握了如何实现一个可变的单向链表。但是之前的链表都是单所有权的,在实际使用中,共享所有权才是更实用的方式,下面一起来看看该如何实现一个不可变的、共享所有权的持久化链表( persistent )。
|
||
|
|
|
||
|
|
开始之前,还需要创建一个新文件 `third.rs` ,并在 `lib.rs` 中添加以下内容:
|
||
|
|
```rust
|
||
|
|
// in lib.rs
|
||
|
|
|
||
|
|
pub mod first;
|
||
|
|
pub mod second;
|
||
|
|
pub mod third;
|
||
|
|
```
|
||
|
|
|
||
|
|
与上一个链表有所不同,这次我们无需拷贝之前的代码,而是从零开始构建一个新的链表。
|
||
|
|
|
||
|
|
|