former_types/collection/
linked_list.rs1use crate::*;
9#[allow(unused)]
10use collection_tools::LinkedList;
11
12impl<E> Collection for LinkedList<E> {
13 type Entry = E;
14 type Val = E;
15
16 #[inline(always)]
17 fn entry_to_val(e: Self::Entry) -> Self::Val {
18 e
19 }
20}
21
22impl<E> CollectionAdd for LinkedList<E> {
23 #[inline(always)]
24 fn add(&mut self, e: Self::Entry) -> bool {
25 self.push_back(e);
26 true
27 }
28}
29
30impl<E> CollectionAssign for LinkedList<E> {
31 #[inline(always)]
32 fn assign<Elements>(&mut self, elements: Elements) -> usize
33 where
34 Elements: IntoIterator<Item = Self::Entry>,
35 {
36 let initial_len = self.len();
37 self.extend(elements);
38 self.len() - initial_len
39 }
40}
41
42impl<E> CollectionValToEntry<E> for LinkedList<E> {
43 type Entry = E;
44 #[inline(always)]
45 fn val_to_entry(val: E) -> Self::Entry {
46 val
47 }
48}
49
50impl<E> Storage for LinkedList<E> {
53 type Preformed = LinkedList<E>;
54}
55
56impl<E> StoragePreform for LinkedList<E> {
57 fn preform(self) -> Self::Preformed {
58 self
59 }
60}
61
62#[derive(Debug, Default)]
77pub struct LinkedListDefinition<E, Context, Formed, End>
78where
79 End: FormingEnd<LinkedListDefinitionTypes<E, Context, Formed>>,
80{
81 _phantom: core::marker::PhantomData<(E, Context, Formed, End)>,
82}
83
84impl<E, Context, Formed, End> FormerDefinition for LinkedListDefinition<E, Context, Formed, End>
85where
86 End: FormingEnd<LinkedListDefinitionTypes<E, Context, Formed>>,
87{
88 type Storage = LinkedList<E>;
89 type Context = Context;
90 type Formed = Formed;
91
92 type Types = LinkedListDefinitionTypes<E, Context, Formed>;
93 type End = End;
94}
95
96#[derive(Debug, Default)]
111pub struct LinkedListDefinitionTypes<E, Context = (), Formed = LinkedList<E>> {
112 _phantom: core::marker::PhantomData<(E, Context, Formed)>,
113}
114
115impl<E, Context, Formed> FormerDefinitionTypes for LinkedListDefinitionTypes<E, Context, Formed> {
116 type Storage = LinkedList<E>;
117 type Context = Context;
118 type Formed = Formed;
119}
120
121impl<E, Context, Formed> FormerMutator for LinkedListDefinitionTypes<E, Context, Formed> {}
124
125impl<E, Definition> EntityToFormer<Definition> for LinkedList<E>
128where
129 Definition: FormerDefinition<
130 Storage = LinkedList<E>,
131 Types = LinkedListDefinitionTypes<
132 E,
133 <Definition as definition::FormerDefinition>::Context,
134 <Definition as definition::FormerDefinition>::Formed,
135 >,
136 >,
137 Definition::End: forming::FormingEnd<Definition::Types>,
138{
139 type Former = LinkedListFormer<E, Definition::Context, Definition::Formed, Definition::End>;
140}
141
142impl<E> crate::EntityToStorage for LinkedList<E> {
143 type Storage = LinkedList<E>;
144}
145
146impl<E, Context, Formed, End> crate::EntityToDefinition<Context, Formed, End> for LinkedList<E>
147where
148 End: crate::FormingEnd<LinkedListDefinitionTypes<E, Context, Formed>>,
149{
150 type Definition = LinkedListDefinition<E, Context, Formed, End>;
151 type Types = LinkedListDefinitionTypes<E, Context, Formed>;
152}
153
154impl<E, Context, Formed> crate::EntityToDefinitionTypes<Context, Formed> for LinkedList<E> {
155 type Types = LinkedListDefinitionTypes<E, Context, Formed>;
156}
157
158pub type LinkedListFormer<E, Context, Formed, End> = CollectionFormer<E, LinkedListDefinition<E, Context, Formed, End>>;
172
173pub trait LinkedListExt<E>: sealed::Sealed {
183 fn former() -> LinkedListFormer<E, (), LinkedList<E>, ReturnStorage>;
185}
186
187impl<E> LinkedListExt<E> for LinkedList<E> {
188 #[allow(clippy::default_constructed_unit_structs)]
189 fn former() -> LinkedListFormer<E, (), LinkedList<E>, ReturnStorage> {
190 LinkedListFormer::<E, (), LinkedList<E>, ReturnStorage>::new(ReturnStorage::default())
191 }
192}
193
194mod sealed {
195 pub trait Sealed {}
196 impl<E> Sealed for super::LinkedList<E> {}
197}