repr/
seq.rs

1use alloc::{vec, vec::Vec};
2use core::ops::Deref;
3
4use unconst::unconst;
5
6use crate::traits::Integral;
7
8#[unconst]
9#[derive_const(Clone, PartialEq, PartialOrd, Ord)]
10#[derive(Debug, Eq)]
11pub struct Seq<I: const Integral>(Vec<I>);
12
13#[unconst]
14impl<I: const Integral> Seq<I> {
15    pub const fn empty() -> Self {
16        Seq(Vec::new())
17    }
18
19    pub const fn new<M: [const] IntoIterator<Item = I>>(is: M) -> Self {
20        Seq(is.into_iter().collect())
21    }
22
23    pub const fn one(i: I) -> Self {
24        Seq(vec![i])
25    }
26
27    #[allow(clippy::should_implement_trait)]
28    pub const fn mul(mut self, other: Self) -> Self {
29        self.0.extend(other);
30        self
31    }
32
33    pub const fn rev(self) -> Self {
34        Seq(self.0.into_iter().rev().collect())
35    }
36
37    pub const fn len(&self) -> usize {
38        self.0.len()
39    }
40}
41
42#[unconst]
43impl<I: const Integral> const AsRef<[I]> for Seq<I> {
44    fn as_ref(&self) -> &[I] {
45        &self.0
46    }
47}
48
49#[unconst]
50impl<I: const Integral> const Deref for Seq<I> {
51    type Target = Vec<I>;
52    fn deref(&self) -> &Vec<I> {
53        &self.0
54    }
55}
56
57#[unconst]
58impl<I: const Integral> const IntoIterator for Seq<I> {
59    type Item = I;
60    type IntoIter = <Vec<I> as IntoIterator>::IntoIter;
61
62    fn into_iter(self) -> Self::IntoIter {
63        self.0.into_iter()
64    }
65}