diff options
author | Aymeric Fromherz | 2024-05-24 15:02:26 +0200 |
---|---|---|
committer | Aymeric Fromherz | 2024-05-24 15:02:26 +0200 |
commit | 4d33ea68ca1ebfca35b7d7332f63b74dd3c06838 (patch) | |
tree | 838da53ae7e5be27e1dde684d0354a5ce2a1fd99 /tests/src/polonius_list.rs | |
parent | ac5f261997079002a782217ebf0c854e31bb880d (diff) | |
parent | 3c8ea6df20f92be9c341bbfb748f65d6c598fead (diff) |
Merge remote-tracking branch 'origin/main' into afromher_debug
Diffstat (limited to 'tests/src/polonius_list.rs')
-rw-r--r-- | tests/src/polonius_list.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/src/polonius_list.rs b/tests/src/polonius_list.rs new file mode 100644 index 00000000..8c64110d --- /dev/null +++ b/tests/src/polonius_list.rs @@ -0,0 +1,27 @@ +#![allow(dead_code)] + +pub enum List<T> { + Cons(T, Box<List<T>>), + Nil, +} + +/// An example which comes from the b-epsilon tree. +/// +/// Returns a mutable borrow to the first portion of the list where we +/// can find [x]. This allows to do in-place modifications (insertion, filtering) +/// in a natural manner (this piece of code was inspired by the C++ BeTree). +pub fn get_list_at_x<'a>(ls: &'a mut List<u32>, x: u32) -> &'a mut List<u32> { + match ls { + List::Nil => { + // We reached the end: just return it + ls + } + List::Cons(hd, tl) => { + if *hd == x { + ls // Doing this requires NLL + } else { + get_list_at_x(tl, x) + } + } + } +} |