const generic expr based fixed length array manipulation crate
bendn 4 months ago
parent e607c4f · commit 5606e40
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs8
-rw-r--r--src/slice.rs25
3 files changed, 8 insertions, 27 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 012a1f3..847c3c9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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]>"]
diff --git a/src/lib.rs b/src/lib.rs
index 7536296..2caa5af 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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]