deepmesa_collections/linkedlist/traits.rs
1/*
2 Linked List: A fast and flexible doubly linked list that
3 allows for O(1) inserts and removes from the middle of the
4 list. This list preallocates memory and doesn't have to allocate
5 and deallocate memory on every insert / remove operation
6
7 Copyright 2021 "Rahul Singh <rsingh@arrsingh.com>"
8
9 Licensed under the Apache License, Version 2.0 (the "License");
10 you may not use this file except in compliance with the License.
11 You may obtain a copy of the License at
12
13 http://www.apache.org/licenses/LICENSE-2.0
14
15 Unless required by applicable law or agreed to in writing, software
16 distributed under the License is distributed on an "AS IS" BASIS,
17 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 See the License for the specific language governing permissions and
19 limitations under the License.
20*/
21
22use crate::linkedlist::list::LinkedList;
23use crate::linkedlist::node::InternalNode;
24
25unsafe impl<T> Send for LinkedList<T> {}
26unsafe impl<T> Sync for LinkedList<T> {}
27
28impl<T> Drop for LinkedList<T> {
29 fn drop(&mut self) {
30 let mut cur: *mut InternalNode<T> = self.head;
31 //Create a Vec to store the items so that we don't leak memory
32 // if the Drop implementation of any of the elements of the
33 // LinkedList panics.
34 let mut node_vec = Vec::with_capacity(self.len());
35 while !cur.is_null() {
36 let node = self.pop_ptr(cur);
37 node_vec.push(node);
38 cur = self.head;
39 }
40 }
41}