Crate cdll

source ·
Expand description

Circular doubly linked list. The implementation is inspired by the linux implementation in C .

§Basic usage

use cdll::CircularList;

let mut my_list = CircularList::default();
for x in 1..=5 {
    my_list.add(x);
}

assert_eq!(my_list.remove(), Some(1));
assert_eq!(my_list.pop(), Some(5));

my_list.iter_mut().for_each(|x: &mut i32| *x -= 1);
assert_eq!(my_list.into_iter().collect::<Vec<i32>>(), &[1, 2, 3])

§Safety considerations

This crate uses unsafe code to dereference raw pointers. In order for it to be sound, one has to preserve some invariants (e.g. pointers must be valid). To achieve this, the source code is commented with careful justifications to prove correctness (at least it is a try).

Macros§

  • Create a list with provided elements.

Structs§