Doubly linked list in Rust I have just started learning Rust, and in order to try to get the hang of references, ownership and mutability, I have attempted to make a doubly linked list. It now compiles, and the add function seems to be working as intended.

There is one implementation detail that I am curious about, and in general I'm wondering whether my code violates any good practice. Also, related to this, have I painted myself into any kind of corner if I want to extend this code? (Making add() keep the list ordered, using generics, implementing Iterator, and so on.)

use std::rc::{Rc, Weak};
use std::cell::RefCell;

#[derive(Debug)]
struct Node {
    value: i32,
    next: RefCell&lt;Option&lt;Rc&lt;Node&gt;&gt;&gt;,
    prev: RefCell&lt;Weak&lt;Node&gt;&gt;,
}

impl Node {
    pub fn add(&amp;self, this: &amp;Rc&lt;Node&gt;, i: i32) {
        if let Some(ref r) = *self.next.borrow() {
            r.add(r, i);
            return;
        };
        *self.next.borrow_mut() = Some(Rc::new(Node {
            value: i,
            next: RefCell::new(None),
            prev: RefCell::new(Rc::downgrade(&amp;this)),
        }));
    }
}

#[derive(Debug)]
struct List {
    head: RefCell&lt;Option&lt;Rc&lt;Node&gt;&gt;&gt;,
}

impl List {
    pub fn add(&amp;self, i: i32) {
        if let Some(ref r) = *self.head.borrow() {
            r.add(r, i);
            return;
        };
        *self.head.borrow_mut() = Some(Rc::new(Node {
            value: i,
            next: RefCell::new(None),
            prev: RefCell::new(Weak::new()),
        }));
    }
}

fn main() {
    let list = List {
        head: RefCell::new(None),
    };
    println!("{:?}", list);
    list.add(1);
    list.add(2);
    println!("{:?}", list);
}


The detail I'm curious about is whether the if let parts can be done with a match. Or, more specifically, can it be done without the extra return call. No matter what I tried (both match and if let with else), the borrow() got in the way of the borrow_mut() in the None arm, and I couldn't get the pattern matching to work without the borrow().
Before looking at your code, I want to give a general notice: don't use linked lists. They are almost always the wrong choice of data structure. They are useful primarily pedagogically. 

Furthermore, I should warn you that implementing a doubly-linked list will not look like typical Rust. You can't implement a doubly-linked list in Rust without using escape hatches like Rc, RefCell, or raw pointers. These escape hatches are necessary when doing low level things like implementing a data structure, but normal Rust code avoids them as much as possible. If you want to get used to "thinking in Rust" you should pick a different exercise. 

The first thing about your code I note is that Node::add function. It takes a pointer to itself twice. self and this. Having two different pointers to the same thing is unhelpful. Just drop the &amp;self parameter and refer to this consistently in the function. Then you can call the function as Node::add.

The second thing is that you have RefCells containing Rc's. However, the standard way is to have it the other way around. It should be Rc&lt;RefCell&lt;?&gt;&gt; not RefCell&lt;Rc&lt;?&gt;&gt;. You'll find that your current design does not let you modify the value of each node.

A third thing is the lack of mutable references. Your add method allows adding to your list without the list being mutable. That doesn't really make sense, your add method really should take a mutable reference to the list. You get away with this because of the previous point. 

Finally, you would be better off not using recursion to add the item to the end of list. Recursion is much slower than iteration. It would make more sense to scan through the nodes looking for the end of the list in a loop than in a recursive function call.