non_empty_continuous
Crate for non-empty continuous collections.
Being continuous ends up being useful as this way converting between a type and its regular counterpart becomes a zero-cost operation.
All types utilise #[repr(transparent)].
This crate attempts to reimplement as much functionality as possible from the non-empty counterparts. In many cases, they are drop-in replacements.
Examples
let first_element = 10;
let mut non_empty_vec: = new;
non_empty_vec.reserve;
non_empty_vec.push;
non_empty_vec.push;
_ = non_empty_vec.try_pop;
let non_empty_slice: & = &non_empty_vec;
let non_empty_slice_mut: &mut = &mut non_empty_vec;
let length: NonZeroUsize = non_empty_slice.len;
let non_empty_vec_from_macro = ne_vec!;
Features
smallvec
Exposes NonEmptySmallVec, a non-empty wrapper around SmallVec from the small_vec crate.
let first_element = 10;
let mut non_empty_small_vec: = new;
non_empty_small_vec.reserve;
non_empty_small_vec.push;
non_empty_small_vec.push;
let _: bool = non_empty_small_vec.spilled;
let non_empty_slice: & = &non_empty_small_vec;
let non_empty_slice_mut: &mut = &mut non_empty_small_vec;
let non_empty_smallvec_from_macro = ne_smallvec!;
static_assert_generic
Allows for infalible operations with arrays whose length is checked not to be 0 at compile-time.
let arr = ;
let mut non_empty_vec: = from_arr;
Empty arrays give an error.
let arr2 = ;
let mut non_empty_vec: = from_arr; // !!!
Smallvec static_assert_generic featues also requires smallvec's const_generics feature.
let arr3 = ;
let mut non_empty_small_vec: = from_arr;
License: 0BSD