orx_meta/queue/
multi.rs

1#![allow(dead_code)]
2use crate::queue::{QueueSingle, StQueue};
3
4/// A queue containing multiple (>= 2) elements.
5///
6/// It is composed of two parts:
7/// * `f: Front` is the element in the front of the queue;
8/// * `b: Back` is the queue of remaining elements except for the one in the front.
9///   It can be:
10///   * either a [`QueueSingle`] containing exactly one element in which case length of this
11///     queue is 2,
12///   * or a [`Queue`] containing multiple elements, in which case length of this queue is
13///     greater than 2, `1 + self.b.len()`.
14///
15/// Note that `Queue::new(element)` gives a `QueueSingle` with one element. In order to create
16/// a queue of multiple elements, we need to push at least one more element, such as
17/// `Queue::new(elem1).push(elem2)`.
18#[derive(Clone, Copy, PartialEq, Eq, Debug)]
19pub struct Queue<Front, Back>
20where
21    Back: StQueue,
22{
23    f: Front,
24    b: Back,
25}
26
27impl<F, B> StQueue for Queue<F, B>
28where
29    B: StQueue,
30{
31    type PushBack<Elem> = Queue<F, B::PushBack<Elem>>;
32
33    type Front = F;
34
35    type Back = B;
36
37    const LEN: usize = 1 + B::LEN;
38
39    #[inline(always)]
40    fn front(&self) -> &F {
41        &self.f
42    }
43
44    #[inline(always)]
45    fn front_mut(&mut self) -> &mut F {
46        &mut self.f
47    }
48
49    #[inline(always)]
50    fn into_front(self) -> F {
51        self.f
52    }
53
54    #[inline(always)]
55    fn push<Elem>(self, element: Elem) -> Self::PushBack<Elem> {
56        Queue::from_fb(self.f, self.b.push(element))
57    }
58}
59
60impl<F> Queue<F, QueueSingle<F>> {
61    /// Creates a [`QueueSingle`] with exactly one `element`.
62    ///
63    /// Note that `Queue::new` is equivalent to `QueueSingle::new`. It is introduced for
64    /// convenience allowing us to work only with the multiple element queue type `Queue`.
65    ///
66    /// # Examples
67    ///
68    /// ```
69    /// use orx_meta::queue::*;
70    /// use orx_meta::queue_of;
71    ///
72    /// // creates a QueueSingle
73    /// let queue: QueueSingle<u32> = Queue::new(42);
74    /// assert_eq!(queue.len(), 1);
75    /// assert_eq!(queue.front(), &42);
76    ///
77    /// // creates a Queue when we push at least one more element
78    /// let queue: Queue<u32, QueueSingle<char>> = Queue::new(42).push('x');
79    /// assert_eq!(queue.len(), 2);
80    ///
81    /// let queue: Queue<u32, Queue<char, Queue<bool, QueueSingle<String>>>>
82    ///   = Queue::new(42).push('x').push(true).push("foo".to_string());
83    /// assert_eq!(queue.as_tuple(), (&42, &'x', &true, &"foo".to_string()));
84    ///
85    /// // equivalently, we can use the queue_of macro to create the type
86    /// let queue: queue_of!(u32, char, bool, String)
87    ///   = Queue::new(42).push('x').push(true).push("foo".to_string());
88    /// assert_eq!(queue.as_tuple(), (&42, &'x', &true, &"foo".to_string()));
89    /// ```
90    #[inline(always)]
91    #[allow(clippy::new_ret_no_self)]
92    pub fn new(element: F) -> QueueSingle<F> {
93        QueueSingle::new(element)
94    }
95}
96
97impl<F, B> Queue<F, B>
98where
99    B: StQueue,
100{
101    #[inline(always)]
102    pub(super) fn from_fb(front: F, back: B) -> Self {
103        Self { f: front, b: back }
104    }
105}
106
107impl<F, B> Queue<F, B>
108where
109    B: StQueue,
110{
111    // ref
112
113    /// Returns a reference to the queue including elements of this queue
114    /// excluding the element in the front.
115    ///
116    /// Note that accessing elements of the queue is always by `front`, while
117    /// `back` allows to access elements in all positions of the queue.
118    ///
119    /// # Examples
120    ///
121    /// ```
122    /// use orx_meta::queue::*;
123    ///
124    /// let queue = Queue::new(42);
125    /// assert_eq!(queue.front(), &42);
126    /// // assert_eq!(queue.back(), ??); // wont' compile, QueueSingle has no back
127    ///
128    /// let queue = Queue::new(42).push(true).push('x').push("foo");
129    /// assert_eq!(queue.back(), &Queue::new(true).push('x').push("foo"));
130    /// assert_eq!(queue.front(), &42);
131    /// assert_eq!(queue.back().front(), &true);
132    /// assert_eq!(queue.back().back().front(), &'x');
133    /// assert_eq!(queue.back().back().back().front(), &"foo");
134    ///
135    /// let (num, queue) = queue.pop();
136    /// assert_eq!(num, 42);
137    /// assert_eq!(queue.front(), &true);
138    /// assert_eq!(queue.back(), &Queue::new('x').push("foo"));
139    ///
140    /// let (flag, queue) = queue.pop();
141    /// assert_eq!(flag, true);
142    /// assert_eq!(queue.front(), &'x');
143    /// assert_eq!(queue.back(), &Queue::new("foo"));
144    ///
145    /// let (c, queue) = queue.pop();
146    /// assert_eq!(c, 'x');
147    /// assert_eq!(queue.front(), &"foo");
148    /// // assert_eq!(queue.back(), ??);  // wont' compile, QueueSingle has no back
149    ///
150    /// let s = queue.pop();
151    /// assert_eq!(s, "foo");
152    /// ```
153    #[inline(always)]
154    pub fn back(&self) -> &B {
155        &self.b
156    }
157
158    // mut
159
160    /// Returns a mutable reference to the queue including elements of this queue
161    /// excluding the element in the front.
162    ///
163    /// Note that mutating elements of the queue is always by `front_mut`, while
164    /// `back_mut` allows to access elements in all positions of the queue.
165    ///
166    /// # Examples
167    ///
168    /// ```
169    /// use orx_meta::queue::*;
170    ///
171    /// let mut queue = Queue::new(42).push(true).push('x');
172    ///
173    /// *queue.front_mut() *= 2;
174    /// *queue.back_mut().front_mut() = false;
175    /// *queue.back_mut().back_mut().front_mut() = 'y';
176    ///
177    /// assert_eq!(queue.as_tuple(), (&84, &false, &'y'));
178    /// ```
179    #[inline(always)]
180    pub fn back_mut(&mut self) -> &mut B {
181        &mut self.b
182    }
183
184    /// Returns a pair of mutable references:
185    /// * first to the element in the front of the queue, and
186    /// * second to the back queue containing elements except for the front.
187    ///
188    /// # Safety
189    ///
190    /// Assume we have a queue of three elements and we want to mutate the first and
191    /// third elements as follows.
192    ///
193    /// However, the following code would not compile.
194    ///
195    /// ```compile_fail
196    /// use orx_meta::queue::*;
197    ///
198    /// let mut q = Queue::new(3).push(true).push('x');
199    ///
200    /// let first = q.front_mut();
201    /// let third = q.back_mut().back_mut().front_mut();
202    ///
203    /// // these calls can be made concurrently
204    /// *first *= 2;
205    /// *third = 'y';
206    /// ```
207    ///
208    /// It is perfectly safe to mutate the first and third elements at the same time.
209    /// Actually, we can mutate all of the elements concurrently.
210    ///
211    /// However, we need to help the compiler to figure this out, which is why we get
212    /// the mutable references to the front and back at the same time. With this, the
213    /// compiler understands that there is no overlap between them.
214    ///
215    /// # Examples
216    ///
217    /// So the following code would compile and work expectedly.
218    ///
219    /// ```
220    /// use orx_meta::queue::*;
221    ///
222    /// let mut q = Queue::new(3).push(true).push('x');
223    ///
224    /// let (first, q23) = q.front_back_mut();
225    /// let third = q23.back_mut().front_mut();
226    ///
227    /// // these calls can be made concurrently
228    /// *first *= 2;
229    /// *third = 'y';
230    ///
231    /// assert_eq!(q.as_tuple(), (&6, &true, &'y'));
232    /// ```
233    #[inline(always)]
234    pub fn front_back_mut(&mut self) -> (&mut F, &mut B) {
235        (&mut self.f, &mut self.b)
236    }
237
238    // into
239
240    /// Consumes the queue and returns the queue including elements of this queue
241    /// except for the element in the front.
242    ///
243    /// Equivalent to `queue.pop().1`.
244    #[inline(always)]
245    pub fn into_back(self) -> B {
246        self.b
247    }
248
249    /// Consumes the queue and returns the tuple of its front and back:
250    ///
251    /// * **front** is the element in the front of this queue.
252    /// * **back** is the queue including all elements of this queue except
253    ///   for the front element. In other words, it is the queue obtained by
254    ///   popping the front element.
255    ///
256    /// # Examples
257    ///
258    /// ```
259    /// use orx_meta::queue::*;
260    ///
261    /// let queue = Queue::new(42);
262    /// let num = queue.pop(); // QueueSingle::pop just returns the front
263    /// assert_eq!(num, 42);
264    ///
265    /// let queue = Queue::new(42).push(true).push('x').push("foo");
266    ///
267    /// let (num, queue) = queue.pop(); // Queue::pop returns (front, back)
268    /// assert_eq!(num, 42);
269    /// assert_eq!(queue, Queue::new(true).push('x').push("foo"));
270    ///
271    /// let (flag, queue) = queue.pop();
272    /// assert_eq!(flag, true);
273    /// assert_eq!(queue, Queue::new('x').push("foo"));
274    ///
275    /// let (c, queue) = queue.pop();
276    /// assert_eq!(c, 'x');
277    /// assert_eq!(queue, Queue::new("foo"));
278    ///
279    /// let s = queue.pop();
280    /// assert_eq!(s, "foo");
281    /// ```
282    #[inline(always)]
283    pub fn pop(self) -> (F, B) {
284        (self.f, self.b)
285    }
286}
287
288// tuple
289
290type S<F> = QueueSingle<F>;
291
292impl<X1> S<X1> {
293    /// Converts the queue into its flat tuple representation.
294    ///
295    /// # Examples
296    ///
297    /// ```
298    /// use orx_meta::queue::*;
299    ///
300    /// let queue = Queue::new(42);
301    /// assert_eq!(queue.into_tuple(), 42);
302    ///
303    /// let queue = Queue::new(42).push(true);
304    /// assert_eq!(queue.into_tuple(), (42, true));
305    ///
306    /// let queue = Queue::new(42).push(true).push('x').push("foo");
307    /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
308    /// ```
309    pub fn into_tuple(self) -> X1 {
310        self.front
311    }
312    /// Returns a flat tuple representation of references to elements in the queue.
313    ///
314    /// # Examples
315    ///
316    /// ```
317    /// use orx_meta::queue::*;
318    ///
319    /// let queue = Queue::new(42);
320    /// assert_eq!(queue.as_tuple(), &42);
321    ///
322    /// let queue = Queue::new(42).push(true);
323    /// assert_eq!(queue.as_tuple(), (&42, &true));
324    ///
325    /// let queue = Queue::new(42).push(true).push('x').push("foo");
326    /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
327    /// ```
328    pub fn as_tuple(&self) -> &X1 {
329        &self.front
330    }
331    /// Returns a flat tuple representation of mutable references to elements in the queue.
332    ///
333    /// # Examples
334    ///
335    /// ```
336    /// use orx_meta::queue::*;
337    ///
338    /// let mut queue = Queue::new(42);
339    /// let a = queue.as_tuple_mut();
340    /// *a *= 2;
341    /// assert_eq!(queue.as_tuple(), &84);
342    ///
343    /// let mut queue = Queue::new(42).push(true);
344    /// let (a, b) = queue.as_tuple_mut();
345    /// *a *= 2;
346    /// *b = false;
347    /// assert_eq!(queue.as_tuple(), (&84, &false));
348    ///
349    /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
350    /// let (a, b, c, d) = queue.as_tuple_mut();
351    /// *a *= 2;
352    /// *b = false;
353    /// *c = 'y';
354    /// *d = "bar";
355    /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
356    /// ```
357    pub fn as_tuple_mut(&mut self) -> &mut X1 {
358        &mut self.front
359    }
360}
361
362impl<X1, X2> Queue<X1, S<X2>> {
363    /// Converts the queue into its flat tuple representation.
364    ///
365    /// # Examples
366    ///
367    /// ```
368    /// use orx_meta::queue::*;
369    ///
370    /// let queue = Queue::new(42);
371    /// assert_eq!(queue.into_tuple(), 42);
372    ///
373    /// let queue = Queue::new(42).push(true);
374    /// assert_eq!(queue.into_tuple(), (42, true));
375    ///
376    /// let queue = Queue::new(42).push(true).push('x').push("foo");
377    /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
378    /// ```
379    pub fn into_tuple(self) -> (X1, X2) {
380        (self.f, self.b.front)
381    }
382    /// Returns a flat tuple representation of references to elements in the queue.
383    ///
384    /// # Examples
385    ///
386    /// ```
387    /// use orx_meta::queue::*;
388    ///
389    /// let queue = Queue::new(42);
390    /// assert_eq!(queue.as_tuple(), &42);
391    ///
392    /// let queue = Queue::new(42).push(true);
393    /// assert_eq!(queue.as_tuple(), (&42, &true));
394    ///
395    /// let queue = Queue::new(42).push(true).push('x').push("foo");
396    /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
397    /// ```
398    pub fn as_tuple(&self) -> (&X1, &X2) {
399        (&self.f, &self.b.front)
400    }
401    /// Returns a flat tuple representation of mutable references to elements in the queue.
402    ///
403    /// # Examples
404    ///
405    /// ```
406    /// use orx_meta::queue::*;
407    ///
408    /// let mut queue = Queue::new(42);
409    /// let a = queue.as_tuple_mut();
410    /// *a *= 2;
411    /// assert_eq!(queue.as_tuple(), &84);
412    ///
413    /// let mut queue = Queue::new(42).push(true);
414    /// let (a, b) = queue.as_tuple_mut();
415    /// *a *= 2;
416    /// *b = false;
417    /// assert_eq!(queue.as_tuple(), (&84, &false));
418    ///
419    /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
420    /// let (a, b, c, d) = queue.as_tuple_mut();
421    /// *a *= 2;
422    /// *b = false;
423    /// *c = 'y';
424    /// *d = "bar";
425    /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
426    /// ```
427    pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2) {
428        (&mut self.f, &mut self.b.front)
429    }
430}
431
432impl<X1, X2, X3> Queue<X1, Queue<X2, S<X3>>> {
433    /// Converts the queue into its flat tuple representation.
434    ///
435    /// # Examples
436    ///
437    /// ```
438    /// use orx_meta::queue::*;
439    ///
440    /// let queue = Queue::new(42);
441    /// assert_eq!(queue.into_tuple(), 42);
442    ///
443    /// let queue = Queue::new(42).push(true);
444    /// assert_eq!(queue.into_tuple(), (42, true));
445    ///
446    /// let queue = Queue::new(42).push(true).push('x').push("foo");
447    /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
448    /// ```
449    pub fn into_tuple(self) -> (X1, X2, X3) {
450        (self.f, self.b.f, self.b.b.front)
451    }
452    /// Returns a flat tuple representation of references to elements in the queue.
453    ///
454    /// # Examples
455    ///
456    /// ```
457    /// use orx_meta::queue::*;
458    ///
459    /// let queue = Queue::new(42);
460    /// assert_eq!(queue.as_tuple(), &42);
461    ///
462    /// let queue = Queue::new(42).push(true);
463    /// assert_eq!(queue.as_tuple(), (&42, &true));
464    ///
465    /// let queue = Queue::new(42).push(true).push('x').push("foo");
466    /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
467    /// ```
468    pub fn as_tuple(&self) -> (&X1, &X2, &X3) {
469        (&self.f, &self.b.f, &self.b.b.front)
470    }
471    /// Returns a flat tuple representation of mutable references to elements in the queue.
472    ///
473    /// # Examples
474    ///
475    /// ```
476    /// use orx_meta::queue::*;
477    ///
478    /// let mut queue = Queue::new(42);
479    /// let a = queue.as_tuple_mut();
480    /// *a *= 2;
481    /// assert_eq!(queue.as_tuple(), &84);
482    ///
483    /// let mut queue = Queue::new(42).push(true);
484    /// let (a, b) = queue.as_tuple_mut();
485    /// *a *= 2;
486    /// *b = false;
487    /// assert_eq!(queue.as_tuple(), (&84, &false));
488    ///
489    /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
490    /// let (a, b, c, d) = queue.as_tuple_mut();
491    /// *a *= 2;
492    /// *b = false;
493    /// *c = 'y';
494    /// *d = "bar";
495    /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
496    /// ```
497    pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3) {
498        (&mut self.f, &mut self.b.f, &mut self.b.b.front)
499    }
500}
501
502impl<X1, X2, X3, X4> Queue<X1, Queue<X2, Queue<X3, S<X4>>>> {
503    /// Converts the queue into its flat tuple representation.
504    ///
505    /// # Examples
506    ///
507    /// ```
508    /// use orx_meta::queue::*;
509    ///
510    /// let queue = Queue::new(42);
511    /// assert_eq!(queue.into_tuple(), 42);
512    ///
513    /// let queue = Queue::new(42).push(true);
514    /// assert_eq!(queue.into_tuple(), (42, true));
515    ///
516    /// let queue = Queue::new(42).push(true).push('x').push("foo");
517    /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
518    /// ```
519    pub fn into_tuple(self) -> (X1, X2, X3, X4) {
520        (self.f, self.b.f, self.b.b.f, self.b.b.b.front)
521    }
522    /// Returns a flat tuple representation of references to elements in the queue.
523    ///
524    /// # Examples
525    ///
526    /// ```
527    /// use orx_meta::queue::*;
528    ///
529    /// let queue = Queue::new(42);
530    /// assert_eq!(queue.as_tuple(), &42);
531    ///
532    /// let queue = Queue::new(42).push(true);
533    /// assert_eq!(queue.as_tuple(), (&42, &true));
534    ///
535    /// let queue = Queue::new(42).push(true).push('x').push("foo");
536    /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
537    /// ```
538    pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4) {
539        (&self.f, &self.b.f, &self.b.b.f, &self.b.b.b.front)
540    }
541    /// Returns a flat tuple representation of mutable references to elements in the queue.
542    ///
543    /// # Examples
544    ///
545    /// ```
546    /// use orx_meta::queue::*;
547    ///
548    /// let mut queue = Queue::new(42);
549    /// let a = queue.as_tuple_mut();
550    /// *a *= 2;
551    /// assert_eq!(queue.as_tuple(), &84);
552    ///
553    /// let mut queue = Queue::new(42).push(true);
554    /// let (a, b) = queue.as_tuple_mut();
555    /// *a *= 2;
556    /// *b = false;
557    /// assert_eq!(queue.as_tuple(), (&84, &false));
558    ///
559    /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
560    /// let (a, b, c, d) = queue.as_tuple_mut();
561    /// *a *= 2;
562    /// *b = false;
563    /// *c = 'y';
564    /// *d = "bar";
565    /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
566    /// ```
567    pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3, &mut X4) {
568        (
569            &mut self.f,
570            &mut self.b.f,
571            &mut self.b.b.f,
572            &mut self.b.b.b.front,
573        )
574    }
575}
576
577impl<X1, X2, X3, X4, X5> Queue<X1, Queue<X2, Queue<X3, Queue<X4, S<X5>>>>> {
578    /// Converts the queue into its flat tuple representation.
579    ///
580    /// # Examples
581    ///
582    /// ```
583    /// use orx_meta::queue::*;
584    ///
585    /// let queue = Queue::new(42);
586    /// assert_eq!(queue.into_tuple(), 42);
587    ///
588    /// let queue = Queue::new(42).push(true);
589    /// assert_eq!(queue.into_tuple(), (42, true));
590    ///
591    /// let queue = Queue::new(42).push(true).push('x').push("foo");
592    /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
593    /// ```
594    pub fn into_tuple(self) -> (X1, X2, X3, X4, X5) {
595        (
596            self.f,
597            self.b.f,
598            self.b.b.f,
599            self.b.b.b.f,
600            self.b.b.b.b.front,
601        )
602    }
603    /// Returns a flat tuple representation of references to elements in the queue.
604    ///
605    /// # Examples
606    ///
607    /// ```
608    /// use orx_meta::queue::*;
609    ///
610    /// let queue = Queue::new(42);
611    /// assert_eq!(queue.as_tuple(), &42);
612    ///
613    /// let queue = Queue::new(42).push(true);
614    /// assert_eq!(queue.as_tuple(), (&42, &true));
615    ///
616    /// let queue = Queue::new(42).push(true).push('x').push("foo");
617    /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
618    /// ```
619    pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5) {
620        (
621            &self.f,
622            &self.b.f,
623            &self.b.b.f,
624            &self.b.b.b.f,
625            &self.b.b.b.b.front,
626        )
627    }
628    /// Returns a flat tuple representation of mutable references to elements in the queue.
629    ///
630    /// # Examples
631    ///
632    /// ```
633    /// use orx_meta::queue::*;
634    ///
635    /// let mut queue = Queue::new(42);
636    /// let a = queue.as_tuple_mut();
637    /// *a *= 2;
638    /// assert_eq!(queue.as_tuple(), &84);
639    ///
640    /// let mut queue = Queue::new(42).push(true);
641    /// let (a, b) = queue.as_tuple_mut();
642    /// *a *= 2;
643    /// *b = false;
644    /// assert_eq!(queue.as_tuple(), (&84, &false));
645    ///
646    /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
647    /// let (a, b, c, d) = queue.as_tuple_mut();
648    /// *a *= 2;
649    /// *b = false;
650    /// *c = 'y';
651    /// *d = "bar";
652    /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
653    /// ```
654    pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3, &mut X4, &mut X5) {
655        (
656            &mut self.f,
657            &mut self.b.f,
658            &mut self.b.b.f,
659            &mut self.b.b.b.f,
660            &mut self.b.b.b.b.front,
661        )
662    }
663}
664
665impl<X1, X2, X3, X4, X5, X6> Queue<X1, Queue<X2, Queue<X3, Queue<X4, Queue<X5, S<X6>>>>>> {
666    /// Converts the queue into its flat tuple representation.
667    ///
668    /// # Examples
669    ///
670    /// ```
671    /// use orx_meta::queue::*;
672    ///
673    /// let queue = Queue::new(42);
674    /// assert_eq!(queue.into_tuple(), 42);
675    ///
676    /// let queue = Queue::new(42).push(true);
677    /// assert_eq!(queue.into_tuple(), (42, true));
678    ///
679    /// let queue = Queue::new(42).push(true).push('x').push("foo");
680    /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
681    /// ```
682    pub fn into_tuple(self) -> (X1, X2, X3, X4, X5, X6) {
683        (
684            self.f,
685            self.b.f,
686            self.b.b.f,
687            self.b.b.b.f,
688            self.b.b.b.b.f,
689            self.b.b.b.b.b.front,
690        )
691    }
692    /// Returns a flat tuple representation of references to elements in the queue.
693    ///
694    /// # Examples
695    ///
696    /// ```
697    /// use orx_meta::queue::*;
698    ///
699    /// let queue = Queue::new(42);
700    /// assert_eq!(queue.as_tuple(), &42);
701    ///
702    /// let queue = Queue::new(42).push(true);
703    /// assert_eq!(queue.as_tuple(), (&42, &true));
704    ///
705    /// let queue = Queue::new(42).push(true).push('x').push("foo");
706    /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
707    /// ```
708    pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5, &X6) {
709        (
710            &self.f,
711            &self.b.f,
712            &self.b.b.f,
713            &self.b.b.b.f,
714            &self.b.b.b.b.f,
715            &self.b.b.b.b.b.front,
716        )
717    }
718    /// Returns a flat tuple representation of mutable references to elements in the queue.
719    ///
720    /// # Examples
721    ///
722    /// ```
723    /// use orx_meta::queue::*;
724    ///
725    /// let mut queue = Queue::new(42);
726    /// let a = queue.as_tuple_mut();
727    /// *a *= 2;
728    /// assert_eq!(queue.as_tuple(), &84);
729    ///
730    /// let mut queue = Queue::new(42).push(true);
731    /// let (a, b) = queue.as_tuple_mut();
732    /// *a *= 2;
733    /// *b = false;
734    /// assert_eq!(queue.as_tuple(), (&84, &false));
735    ///
736    /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
737    /// let (a, b, c, d) = queue.as_tuple_mut();
738    /// *a *= 2;
739    /// *b = false;
740    /// *c = 'y';
741    /// *d = "bar";
742    /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
743    /// ```
744    pub fn as_tuple_mut(&mut self) -> (&mut X1, &mut X2, &mut X3, &mut X4, &mut X5, &mut X6) {
745        (
746            &mut self.f,
747            &mut self.b.f,
748            &mut self.b.b.f,
749            &mut self.b.b.b.f,
750            &mut self.b.b.b.b.f,
751            &mut self.b.b.b.b.b.front,
752        )
753    }
754}
755
756impl<X1, X2, X3, X4, X5, X6, X7>
757    Queue<X1, Queue<X2, Queue<X3, Queue<X4, Queue<X5, Queue<X6, S<X7>>>>>>>
758{
759    /// Converts the queue into its flat tuple representation.
760    ///
761    /// # Examples
762    ///
763    /// ```
764    /// use orx_meta::queue::*;
765    ///
766    /// let queue = Queue::new(42);
767    /// assert_eq!(queue.into_tuple(), 42);
768    ///
769    /// let queue = Queue::new(42).push(true);
770    /// assert_eq!(queue.into_tuple(), (42, true));
771    ///
772    /// let queue = Queue::new(42).push(true).push('x').push("foo");
773    /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
774    /// ```
775    pub fn into_tuple(self) -> (X1, X2, X3, X4, X5, X6, X7) {
776        (
777            self.f,
778            self.b.f,
779            self.b.b.f,
780            self.b.b.b.f,
781            self.b.b.b.b.f,
782            self.b.b.b.b.b.f,
783            self.b.b.b.b.b.b.front,
784        )
785    }
786    /// Returns a flat tuple representation of references to elements in the queue.
787    ///
788    /// # Examples
789    ///
790    /// ```
791    /// use orx_meta::queue::*;
792    ///
793    /// let queue = Queue::new(42);
794    /// assert_eq!(queue.as_tuple(), &42);
795    ///
796    /// let queue = Queue::new(42).push(true);
797    /// assert_eq!(queue.as_tuple(), (&42, &true));
798    ///
799    /// let queue = Queue::new(42).push(true).push('x').push("foo");
800    /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
801    /// ```
802    pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5, &X6, &X7) {
803        (
804            &self.f,
805            &self.b.f,
806            &self.b.b.f,
807            &self.b.b.b.f,
808            &self.b.b.b.b.f,
809            &self.b.b.b.b.b.f,
810            &self.b.b.b.b.b.b.front,
811        )
812    }
813    /// Returns a flat tuple representation of mutable references to elements in the queue.
814    ///
815    /// # Examples
816    ///
817    /// ```
818    /// use orx_meta::queue::*;
819    ///
820    /// let mut queue = Queue::new(42);
821    /// let a = queue.as_tuple_mut();
822    /// *a *= 2;
823    /// assert_eq!(queue.as_tuple(), &84);
824    ///
825    /// let mut queue = Queue::new(42).push(true);
826    /// let (a, b) = queue.as_tuple_mut();
827    /// *a *= 2;
828    /// *b = false;
829    /// assert_eq!(queue.as_tuple(), (&84, &false));
830    ///
831    /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
832    /// let (a, b, c, d) = queue.as_tuple_mut();
833    /// *a *= 2;
834    /// *b = false;
835    /// *c = 'y';
836    /// *d = "bar";
837    /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
838    /// ```
839    pub fn as_tuple_mut(
840        &mut self,
841    ) -> (
842        &mut X1,
843        &mut X2,
844        &mut X3,
845        &mut X4,
846        &mut X5,
847        &mut X6,
848        &mut X7,
849    ) {
850        (
851            &mut self.f,
852            &mut self.b.f,
853            &mut self.b.b.f,
854            &mut self.b.b.b.f,
855            &mut self.b.b.b.b.f,
856            &mut self.b.b.b.b.b.f,
857            &mut self.b.b.b.b.b.b.front,
858        )
859    }
860}
861
862impl<X1, X2, X3, X4, X5, X6, X7, X8>
863    Queue<X1, Queue<X2, Queue<X3, Queue<X4, Queue<X5, Queue<X6, Queue<X7, S<X8>>>>>>>>
864{
865    /// Converts the queue into its flat tuple representation.
866    ///
867    /// # Examples
868    ///
869    /// ```
870    /// use orx_meta::queue::*;
871    ///
872    /// let queue = Queue::new(42);
873    /// assert_eq!(queue.into_tuple(), 42);
874    ///
875    /// let queue = Queue::new(42).push(true);
876    /// assert_eq!(queue.into_tuple(), (42, true));
877    ///
878    /// let queue = Queue::new(42).push(true).push('x').push("foo");
879    /// assert_eq!(queue.into_tuple(), (42, true, 'x', "foo"));
880    /// ```
881    pub fn into_tuple(self) -> (X1, X2, X3, X4, X5, X6, X7, X8) {
882        (
883            self.f,
884            self.b.f,
885            self.b.b.f,
886            self.b.b.b.f,
887            self.b.b.b.b.f,
888            self.b.b.b.b.b.f,
889            self.b.b.b.b.b.b.f,
890            self.b.b.b.b.b.b.b.front,
891        )
892    }
893    /// Returns a flat tuple representation of references to elements in the queue.
894    ///
895    /// # Examples
896    ///
897    /// ```
898    /// use orx_meta::queue::*;
899    ///
900    /// let queue = Queue::new(42);
901    /// assert_eq!(queue.as_tuple(), &42);
902    ///
903    /// let queue = Queue::new(42).push(true);
904    /// assert_eq!(queue.as_tuple(), (&42, &true));
905    ///
906    /// let queue = Queue::new(42).push(true).push('x').push("foo");
907    /// assert_eq!(queue.as_tuple(), (&42, &true, &'x', &"foo"));
908    /// ```
909    pub fn as_tuple(&self) -> (&X1, &X2, &X3, &X4, &X5, &X6, &X7, &X8) {
910        (
911            &self.f,
912            &self.b.f,
913            &self.b.b.f,
914            &self.b.b.b.f,
915            &self.b.b.b.b.f,
916            &self.b.b.b.b.b.f,
917            &self.b.b.b.b.b.b.f,
918            &self.b.b.b.b.b.b.b.front,
919        )
920    }
921    /// Returns a flat tuple representation of mutable references to elements in the queue.
922    ///
923    /// # Examples
924    ///
925    /// ```
926    /// use orx_meta::queue::*;
927    ///
928    /// let mut queue = Queue::new(42);
929    /// let a = queue.as_tuple_mut();
930    /// *a *= 2;
931    /// assert_eq!(queue.as_tuple(), &84);
932    ///
933    /// let mut queue = Queue::new(42).push(true);
934    /// let (a, b) = queue.as_tuple_mut();
935    /// *a *= 2;
936    /// *b = false;
937    /// assert_eq!(queue.as_tuple(), (&84, &false));
938    ///
939    /// let mut queue = Queue::new(42).push(true).push('x').push("foo");
940    /// let (a, b, c, d) = queue.as_tuple_mut();
941    /// *a *= 2;
942    /// *b = false;
943    /// *c = 'y';
944    /// *d = "bar";
945    /// assert_eq!(queue.as_tuple(), (&84, &false, &'y', &"bar"));
946    /// ```
947    pub fn as_tuple_mut(
948        &mut self,
949    ) -> (
950        &mut X1,
951        &mut X2,
952        &mut X3,
953        &mut X4,
954        &mut X5,
955        &mut X6,
956        &mut X7,
957        &mut X8,
958    ) {
959        (
960            &mut self.f,
961            &mut self.b.f,
962            &mut self.b.b.f,
963            &mut self.b.b.b.f,
964            &mut self.b.b.b.b.f,
965            &mut self.b.b.b.b.b.f,
966            &mut self.b.b.b.b.b.b.f,
967            &mut self.b.b.b.b.b.b.b.front,
968        )
969    }
970}