List is a doubly linked list stored in one contiguous allocation.

O(1) insert and remove both at front and back.

O(1) insert anywhere if you have a cursor to that position.

Only use of unsafe is an unavoidable use for IterMut.

It is similar to a linked list in a language like C, except instead of pointers we use indices into a backing vector.

The list is just a vector, and indices to the head and tail:

struct List < T > { link : [ usize ; 2 ], nodes : Vec < Node < T >> , }

The list node is represented like this:

struct Node < T > { link : [ usize ; 2 ], value : T , }

The link arrays contain the vector indices of the previous and next node. We use an array so that symmetries in front/back or prev/next can be used easily in the code — it's nice if we can write just one push and one pop method instead of two.

There is a constant to denote a “null” index, and that's usize's max value. We don't always have to check for this case, we can just access the nodes vector using .get() or .get_mut(); a “null” link is the None case.

List could be generic over the index type, so that internal prev/node links can use less space than a regular pointer (can be u16 or u32 index).

With some cleanup we can use unchecked indexing — but it's not guaranteed to make any difference.