diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 985dea0..d2a8331 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -34,7 +34,7 @@ jobs: - name: Test non nightly if: matrix.rust != '1.47.0' && matrix.rust != 'nightly' run: | - cargo test --features=alloc,std,grab_spare_slice + cargo test --features=alloc,std,grab_spare_slice,latest_stable_rust - name: Test on Nightly with All Features if: matrix.rust == 'nightly' run: | diff --git a/Cargo.toml b/Cargo.toml index f46fc01..aef393d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,11 @@ rustc_1_57 = ["rustc_1_55"] # add retain_mut function to TinyVec rustc_1_61 = ["rustc_1_57"] +# We're done with per-version featuring, this feature opts in to all the +# abilities of the latest release of Stable rust, and we don't need a million +# features forever now. +latest_stable_rust = ["rustc_1_61"] + # allow use of nightly feature `slice_partition_dedup`, # will become useless once that is stabilized: # https://github.com/rust-lang/rust/issues/54279 @@ -67,11 +72,11 @@ experimental_write_impl = [] real_blackbox = ["criterion/real_blackbox"] [package.metadata.docs.rs] -features = ["alloc", "std", "grab_spare_slice", "rustc_1_55", "serde"] -rustdoc-args = ["--cfg","docs_rs"] +features = ["alloc", "std", "grab_spare_slice", "latest_stable_rust", "serde"] +rustdoc-args = ["--cfg", "docs_rs"] [package.metadata.playground] -features = ["alloc", "std", "grab_spare_slice", "rustc_1_55", "serde"] +features = ["alloc", "std", "grab_spare_slice", "latest_stable_rust", "serde"] [profile.bench] debug = 2 diff --git a/src/arrayvec.rs b/src/arrayvec.rs index 94b6fc7..070bca9 100644 --- a/src/arrayvec.rs +++ b/src/arrayvec.rs @@ -1071,6 +1071,7 @@ impl ArrayVec { /// If the given length is greater than the capacity of the array this will /// error, and you'll get the array back in the `Err`. #[inline] + #[cfg(not(feature = "latest_stable_rust"))] pub fn try_from_array_len(data: A, len: usize) -> Result { /* Note(Soveu): Should we allow A::CAPACITY > u16::MAX for now? */ if len <= A::CAPACITY { @@ -1079,6 +1080,26 @@ impl ArrayVec { Err(data) } } + + /// Wraps an array, using the given length as the starting length. + /// + /// If you want to use the whole length of the array, you can just use the + /// `From` impl. + /// + /// ## Failure + /// + /// If the given length is greater than the capacity of the array this will + /// error, and you'll get the array back in the `Err`. + #[inline] + #[cfg(feature = "latest_stable_rust")] + pub const fn try_from_array_len(data: A, len: usize) -> Result { + /* Note(Soveu): Should we allow A::CAPACITY > u16::MAX for now? */ + if len <= A::CAPACITY { + Ok(Self { data, len: len as u16 }) + } else { + Err(data) + } + } } impl ArrayVec { @@ -1883,6 +1904,7 @@ impl ArrayVec { /// assert_eq!(v, &[1, 2, 3]); /// assert_eq!(v.capacity(), 13); /// ``` + #[inline] #[cfg(feature = "rustc_1_57")] pub fn try_drain_to_vec_and_reserve( &mut self, n: usize, @@ -1925,6 +1947,7 @@ impl ArrayVec { /// // Vec may reserve more than necessary in order to prevent more future allocations. /// assert!(v.capacity() >= 3); /// ``` + #[inline] #[cfg(feature = "rustc_1_57")] pub fn try_drain_to_vec(&mut self) -> Result, TryReserveError> { self.try_drain_to_vec_and_reserve(0) diff --git a/src/tinyvec.rs b/src/tinyvec.rs index 953a47a..89883c7 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -316,6 +316,7 @@ impl TinyVec { /// assert_eq!(Ok(()), tv.try_move_to_the_heap()); /// assert!(tv.is_heap()); /// ``` + #[inline] #[cfg(feature = "rustc_1_57")] pub fn try_move_to_the_heap(&mut self) -> Result<(), TryReserveError> { let arr = match self { @@ -364,6 +365,7 @@ impl TinyVec { /// assert!(tv.is_heap()); /// assert!(tv.capacity() >= 35); /// ``` + #[inline] #[cfg(feature = "rustc_1_57")] pub fn try_move_to_the_heap_and_reserve( &mut self, n: usize, @@ -419,6 +421,7 @@ impl TinyVec { /// assert!(tv.is_heap()); /// assert!(tv.capacity() >= 5); /// ``` + #[inline] #[cfg(feature = "rustc_1_57")] pub fn try_reserve(&mut self, n: usize) -> Result<(), TryReserveError> { let arr = match self { @@ -489,6 +492,7 @@ impl TinyVec { /// assert!(tv.is_heap()); /// assert!(tv.capacity() >= 5); /// ``` + #[inline] #[cfg(feature = "rustc_1_57")] pub fn try_reserve_exact(&mut self, n: usize) -> Result<(), TryReserveError> { let arr = match self {