From 064ff239f373daf93d73d73eaf7dc7bece05ef0e Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Sun, 6 Jun 2021 14:56:00 -0700 Subject: [PATCH] Allow zero sized LinkedList --- src/linked_list.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/linked_list.rs b/src/linked_list.rs index 6a9836eee2..3a0bda0e69 100644 --- a/src/linked_list.rs +++ b/src/linked_list.rs @@ -269,6 +269,11 @@ where let len = N::U16; let mut free = 0; + if len == 0 { + list.free = LinkedIndex::none(); + return list; + } + // Initialize indexes while free < len - 1 { unsafe { @@ -557,6 +562,13 @@ mod tests { assert!(ll.is_empty()) } + #[test] + fn test_zero_size() { + let ll: LinkedList = LinkedList::new(); + + assert!(ll.is_full()); + } + #[test] fn test_rejected_push() { let mut ll: LinkedList = LinkedList::new();