Skip to main content

ferroui_base/collections/
i_ferro_list.rs

1use super::{FerroList, IFerroReadOnlyList};
2
3/// A notifying list.
4///
5/// The members of the list contract it extends (add, insert, remove,
6/// search) are part of the trait. Ranges are passed as vectors, so that the
7/// trait can be used as an object.
8pub trait IFerroList<T>: IFerroReadOnlyList<T> {
9    /// Sets the element at the specified index.
10    fn set(&self, index: usize, value: T);
11
12    /// Adds an item to the collection.
13    fn add(&self, item: T);
14
15    /// Inserts an item at the specified index.
16    fn insert(&self, index: usize, item: T);
17
18    /// Removes the item at the specified index.
19    fn remove_at(&self, index: usize);
20
21    /// Removes all items from the collection.
22    fn clear(&self);
23
24    /// Tests whether the collection contains an item.
25    fn contains(&self, item: &T) -> bool;
26
27    /// The index of an item in the collection.
28    fn index_of(&self, item: &T) -> Option<usize>;
29
30    /// Removes an item from the collection. Returns true if it was present.
31    fn remove(&self, item: &T) -> bool;
32
33    /// Adds multiple items to the collection.
34    fn add_range(&self, items: Vec<T>);
35
36    /// Inserts multiple items at the specified index.
37    fn insert_range(&self, index: usize, items: Vec<T>);
38
39    /// Moves an item to a new index.
40    fn move_item(&self, old_index: usize, new_index: usize);
41
42    /// Moves multiple items to a new index.
43    fn move_range(&self, old_index: usize, count: usize, new_index: usize);
44
45    /// Removes multiple items from the collection.
46    fn remove_all(&self, items: Vec<T>);
47
48    /// Removes a range of elements from the collection.
49    fn remove_range(&self, index: usize, count: usize);
50}
51
52impl<T: Clone + PartialEq> IFerroList<T> for FerroList<T> {
53    fn set(&self, index: usize, value: T) {
54        FerroList::set(self, index, value)
55    }
56
57    fn add(&self, item: T) {
58        FerroList::add(self, item)
59    }
60
61    fn insert(&self, index: usize, item: T) {
62        FerroList::insert(self, index, item)
63    }
64
65    fn remove_at(&self, index: usize) {
66        FerroList::remove_at(self, index)
67    }
68
69    fn clear(&self) {
70        FerroList::clear(self)
71    }
72
73    fn contains(&self, item: &T) -> bool {
74        FerroList::contains(self, item)
75    }
76
77    fn index_of(&self, item: &T) -> Option<usize> {
78        FerroList::index_of(self, item)
79    }
80
81    fn remove(&self, item: &T) -> bool {
82        FerroList::remove(self, item)
83    }
84
85    fn add_range(&self, items: Vec<T>) {
86        FerroList::add_range(self, items)
87    }
88
89    fn insert_range(&self, index: usize, items: Vec<T>) {
90        FerroList::insert_range(self, index, items)
91    }
92
93    fn move_item(&self, old_index: usize, new_index: usize) {
94        FerroList::move_item(self, old_index, new_index)
95    }
96
97    fn move_range(&self, old_index: usize, count: usize, new_index: usize) {
98        FerroList::move_range(self, old_index, count, new_index)
99    }
100
101    fn remove_all(&self, items: Vec<T>) {
102        FerroList::remove_all(self, items)
103    }
104
105    fn remove_range(&self, index: usize, count: usize) {
106        FerroList::remove_range(self, index, count)
107    }
108}