1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
#![cfg_attr(feature = "const_generics", allow(incomplete_features))]
#![cfg_attr(feature = "const_generics", feature(generic_const_exprs))]
#![cfg_attr(
feature = "const_generics",
doc(test(attr(allow(incomplete_features))))
)]
#![cfg_attr(
feature = "const_generics",
doc(test(attr(feature(generic_const_exprs))))
)]
#[allow(dead_code)]
#[cfg(test)]
mod tests;
#[cfg(not(feature = "const_generics"))]
mod stable_arr;
#[cfg(feature = "const_generics")]
mod nightly_arr;
#[cfg(feature = "const_generics")]
pub use nightly_arr::*;
/// Trait for defining the removal of the last element from an array- or tuple-like data structure.
pub trait OrdesPop {
/// Type of the container after `.pop()` has been called.
type Newlen;
/// Type of the removed value.
type Output;
/// Remove the last element from `self` and return it.
/// # Examples
/// Using an array:
/// ```
/// # use ordes::OrdesPop;
/// let foo: [u8; 5] = [0, 1, 2, 3, 4];
/// let (foo, pop) = foo.pop();
/// assert_eq!(foo, [0, 1, 2, 3]);
/// assert_eq!(pop, 4);
/// ```
/// Using a tuple:
/// ```
/// # use ordes::OrdesPop;
/// let foo = ('a', false, b'c', "d");
/// let (foo, pop) = foo.pop();
/// assert_eq!(foo, ('a', false, b'c'));
/// assert_eq!(pop, "d");
/// ```
fn pop(self) -> (Self::Newlen, Self::Output);
}
// Consider adding remove?
/// Trait for defining the removal of the first element from an array- or tuple-like data structure.
pub trait OrdesRest {
/// Type of the container after `.rest()` has been called.
type Newlen;
/// Type of the removed value.
type Output;
/// Removes the first element from `self` and returns it.
/// # Examples
/// Using an array:
/// ```
/// # use ordes::OrdesRest;
/// let foo: [u8; 5] = [0, 1, 2, 3, 4];
/// let (foo, pop) = foo.rest();
/// assert_eq!(foo, [1, 2, 3, 4]);
/// assert_eq!(pop, 0);
/// ```
/// Using a tuple:
/// ```
/// # use ordes::OrdesRest;
/// let foo = ('a', false, b'c', "d");
/// let (foo, pop) = foo.rest();
/// assert_eq!(foo, (false, b'c', "d"));
/// assert_eq!(pop, 'a');
/// ```
fn rest(self) -> (Self::Newlen, Self::Output);
}
/// Trait for defining pushing to an array- or tuple-like data structure.
pub trait OrdesPush<Input> {
type Output;
/// Add an element to the end of `self` and return the sum.
/// # Examples
/// Using an array:
/// ```
/// # use ordes::OrdesPush;
/// let foo: [u8; 4] = [0, 1, 2, 3];
/// let foo = foo.push(4);
/// assert_eq!(foo, [0, 1, 2, 3, 4]);
/// ```
/// Using a tuple:
/// ```
/// # use ordes::OrdesPush;
/// let foo = ('a', false, b'c');
/// let foo = foo.push("d");
/// assert_eq!(foo, ('a', false, b'c', "d"));
/// ```
fn push(self, value: Input) -> Self::Output;
// Consider adding insert?
}
pub trait OrdesCons<Input> {
type Output;
/// Add an element to the start of `self` and return the sum.
/// # Examples
/// Using an array:
/// ```
/// # use ordes::OrdesCons;
/// let foo: [u8; 4] = [1, 2, 3, 4];
/// let foo = foo.cons(0);
/// assert_eq!(foo, [0, 1, 2, 3, 4]);
/// ```
/// Using a tuple:
/// ```
/// # use ordes::OrdesCons;
/// let foo = (false, b'c', "d");
/// let foo = foo.cons('a');
/// assert_eq!(foo, ('a', false, b'c', "d"));
/// ```
fn cons(self, value: Input) -> Self::Output;
}
use ordes_macros::impl_ops_tuple;
use seq_macro::seq;
seq! {N in 1..=32 {
impl_ops_tuple!(N);
}}
#[cfg(feature = "len_32_64")]
seq! {N in 33..=64 {
impl_ops_tuple!(N);
}}
#[cfg(feature = "len_64_128")]
seq! {N in 65..=128 {
impl_ops_tuple!(N);
}}
#[cfg(feature = "len_128_256")]
seq! {N in 129..=256 {
impl_ops_tuple!(N);
}}
#[cfg(feature = "len_256_512")]
seq! {N in 257..=512 {
impl_ops_tuple!(N);
}}
#[cfg(feature = "len_512_1024")]
seq! {N in 513..=1024 {
impl_ops_tuple!(N);
}}