1use crate::*;
9#[allow(unused)]
10use collection_tools::BTreeSet;
11
12impl<E> Collection for BTreeSet<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 BTreeSet<E>
23where
24 E: Ord,
25{
26 #[inline(always)]
27 fn add(&mut self, e: Self::Entry) -> bool {
28 self.insert(e);
29 true
30 }
31}
32
33impl<E> CollectionAssign for BTreeSet<E>
34where
35 E: Ord,
36{
37 #[inline(always)]
38 fn assign<Elements>(&mut self, elements: Elements) -> usize
39 where
40 Elements: IntoIterator<Item = Self::Entry>,
41 {
42 let initial_len = self.len();
43 self.extend(elements);
44 self.len() - initial_len
45 }
46}
47
48impl<E> CollectionValToEntry<E> for BTreeSet<E> {
49 type Entry = E;
50 #[inline(always)]
51 fn val_to_entry(val: E) -> Self::Entry {
52 val
53 }
54}
55
56impl<E> Storage for BTreeSet<E> {
59 type Preformed = BTreeSet<E>;
60}
61
62impl<E> StoragePreform for BTreeSet<E> {
63 fn preform(self) -> Self::Preformed {
64 self
65 }
66}
67
68#[derive(Debug, Default)]
83pub struct BTreeSetDefinition<E, Context, Formed, End>
84where
85 End: FormingEnd<BTreeSetDefinitionTypes<E, Context, Formed>>,
86{
87 _phantom: core::marker::PhantomData<(E, Context, Formed, End)>,
88}
89
90impl<E, Context, Formed, End> FormerDefinition for BTreeSetDefinition<E, Context, Formed, End>
91where
92 End: FormingEnd<BTreeSetDefinitionTypes<E, Context, Formed>>,
93{
94 type Storage = BTreeSet<E>;
95 type Context = Context;
96 type Formed = Formed;
97
98 type Types = BTreeSetDefinitionTypes<E, Context, Formed>;
99 type End = End;
100}
101
102#[derive(Debug, Default)]
117pub struct BTreeSetDefinitionTypes<E, Context = (), Formed = BTreeSet<E>> {
118 _phantom: core::marker::PhantomData<(E, Context, Formed)>,
119}
120
121impl<E, Context, Formed> FormerDefinitionTypes for BTreeSetDefinitionTypes<E, Context, Formed> {
122 type Storage = BTreeSet<E>;
123 type Context = Context;
124 type Formed = Formed;
125}
126
127impl<E, Context, Formed> FormerMutator for BTreeSetDefinitionTypes<E, Context, Formed> {}
130
131impl<E, Definition> EntityToFormer<Definition> for BTreeSet<E>
134where
135 E: Ord,
136 Definition: FormerDefinition<
137 Storage = BTreeSet<E>,
138 Types = BTreeSetDefinitionTypes<
139 E,
140 <Definition as definition::FormerDefinition>::Context,
141 <Definition as definition::FormerDefinition>::Formed,
142 >,
143 >,
144 Definition::End: forming::FormingEnd<Definition::Types>,
145{
146 type Former = BTreeSetFormer<E, Definition::Context, Definition::Formed, Definition::End>;
147}
148
149impl<E> crate::EntityToStorage for BTreeSet<E> {
150 type Storage = BTreeSet<E>;
151}
152
153impl<E, Context, Formed, End> crate::EntityToDefinition<Context, Formed, End> for BTreeSet<E>
154where
155 End: crate::FormingEnd<BTreeSetDefinitionTypes<E, Context, Formed>>,
156{
157 type Definition = BTreeSetDefinition<E, Context, Formed, End>;
158 type Types = BTreeSetDefinitionTypes<E, Context, Formed>;
159}
160
161impl<E, Context, Formed> crate::EntityToDefinitionTypes<Context, Formed> for BTreeSet<E> {
162 type Types = BTreeSetDefinitionTypes<E, Context, Formed>;
163}
164
165pub type BTreeSetFormer<E, Context, Formed, End> = CollectionFormer<E, BTreeSetDefinition<E, Context, Formed, End>>;
179
180pub trait BTreeSetExt<E>: sealed::Sealed
190where
191 E: Ord,
192{
193 fn former() -> BTreeSetFormer<E, (), BTreeSet<E>, ReturnStorage>;
195}
196
197impl<E> BTreeSetExt<E> for BTreeSet<E>
198where
199 E: Ord,
200{
201 #[allow(clippy::default_constructed_unit_structs)]
202 fn former() -> BTreeSetFormer<E, (), BTreeSet<E>, ReturnStorage> {
203 BTreeSetFormer::<E, (), BTreeSet<E>, ReturnStorage>::new(ReturnStorage::default())
204 }
205}
206
207mod sealed {
208 pub trait Sealed {}
209 impl<E> Sealed for super::BTreeSet<E> {}
210}