const generic expr based fixed length array manipulation crate
hmm
| -rw-r--r-- | Cargo.toml | 2 | ||||
| -rw-r--r-- | src/lib.rs | 8 | ||||
| -rw-r--r-- | src/slice.rs | 25 |
3 files changed, 8 insertions, 27 deletions
@@ -1,6 +1,6 @@ [package] name = "atools" -version = "0.1.8" +version = "0.1.9" edition = "2021" description = "const generic expr based fixed length array manipulation" authors = ["bend-n <[email protected]>"] @@ -43,7 +43,7 @@ pub mod prelude { #[doc(inline)] pub use super::{ pervasive::prelude::*, range, slice::r, slice::Slice, splat, Array, ArrayTools, Chunked, - CollectArray, Couple, Deconstruct, Flatten, Join, Split, Tuple, Zip, + CollectArray, Couple, Deconstruct, Deconstruct_, Flatten, Join, Split, Tuple, Zip, }; #[doc(inline)] pub use core::array::from_fn; @@ -168,6 +168,12 @@ pub trait Deconstruct_<T, const N: usize> { fn head(self) -> T; /// Gives you a <code>[[_](Deconstruct_::head), tail @ ..]</code>. /// See also [`uncons`](Deconstruct::uncons). + /// ``` + /// # #![feature(generic_const_exprs)] + /// # use atools::prelude::*; + /// let x = atools::range::<5>(); + /// assert!(*x.tail() == atools::range::<4>().map(|x| x + 1)); + /// ``` fn tail(self) -> [T; N - 1]; } diff --git a/src/slice.rs b/src/slice.rs index d44acf5..0221fc9 100644 --- a/src/slice.rs +++ b/src/slice.rs @@ -81,23 +81,6 @@ pub trait Slice<T, const N: usize> { where // comptime length check [(); RANGE.valid::<N>() - 1]:; - - /// Yields all but the last element. - /// ``` - /// # #![feature(generic_const_exprs)] - /// # use atools::prelude::*; - /// let x = atools::range::<5>(); - /// assert!(*x.init() == atools::range::<4>()); - /// ``` - fn init(&self) -> &[T; N - 1]; - /// Yields all but the first element. - /// ``` - /// # #![feature(generic_const_exprs)] - /// # use atools::prelude::*; - /// let x = atools::range::<5>(); - /// assert!(*x.tail() == atools::range::<4>().map(|x| x + 1)); - /// ``` - fn tail(&self) -> &[T; N - 1]; } const unsafe fn slice<T, const N: usize, const TO: usize>(x: &[T; N], begin: usize) -> &[T; TO] { @@ -113,14 +96,6 @@ impl<T, const N: usize> const Slice<T, N> for [T; N] { // SAFETY: the validity check ensures that the array will be in bounds. unsafe { slice::<T, N, { RANGE.length::<N>() }>(self, RANGE.range::<N>().0) } } - - fn init(&self) -> &[T; N - 1] { - unsafe { slice::<T, N, { N - 1 }>(self, 0) } - } - - fn tail(&self) -> &[T; N - 1] { - unsafe { slice::<T, N, { N - 1 }>(self, 1) } - } } #[test] |