diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 35645fd..985dea0 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,7 +11,7 @@ jobs: matrix: os: [ubuntu-latest] rust: - - 1.47.0 + - 1.47.0 # approximate MSRV is Stable -30 - stable - beta - nightly diff --git a/CHANGELOG.md b/CHANGELOG.md index 6430aa3..b40a48d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.8.1 + +* [e00E](https://github.com/e00E) updated the rustc features so that they all + correctly depend on the lower version feature. + [pr 199](https://github.com/Lokathor/tinyvec/pull/199) + ## 1.8 * [Fuuzetsu](https://github.com/Fuuzetsu) added the `ArrayVec::as_inner` method. @@ -68,13 +74,13 @@ ## 1.1.0 * [slightlyoutofphase](https://github.com/slightlyoutofphase) -added "array splat" style syntax to the `array_vec!` and `tiny_vec!` macros. -You can now write `array_vec![true; 5]` and get a length 5 array vec full of `true`, -just like normal array initialization allows. Same goes for `tiny_vec!`. -([pr 118](https://github.com/Lokathor/tinyvec/pull/118)) + added "array splat" style syntax to the `array_vec!` and `tiny_vec!` macros. + You can now write `array_vec![true; 5]` and get a length 5 array vec full of `true`, + just like normal array initialization allows. Same goes for `tiny_vec!`. + ([pr 118](https://github.com/Lokathor/tinyvec/pull/118)) * [not-a-seagull](https://github.com/not-a-seagull) -added `ArrayVec::into_inner` so that you can get the array out of an `ArrayVec`. -([pr 124](https://github.com/Lokathor/tinyvec/pull/124)) + added `ArrayVec::into_inner` so that you can get the array out of an `ArrayVec`. + ([pr 124](https://github.com/Lokathor/tinyvec/pull/124)) ## 1.0.2 diff --git a/src/arrayvec.rs b/src/arrayvec.rs index f40b617..94b6fc7 100644 --- a/src/arrayvec.rs +++ b/src/arrayvec.rs @@ -52,8 +52,8 @@ macro_rules! array_vec { /// An array-backed, vector-like data structure. /// /// * `ArrayVec` has a fixed capacity, equal to the minimum of the array size -/// and `u16::MAX`. Note that not all capacities are necessarily supported by -/// default. See comments in [`Array`]. +/// and `u16::MAX`. Note that not all capacities are necessarily supported by +/// default. See comments in [`Array`]. /// * `ArrayVec` has a variable length, as you add and remove elements. Attempts /// to fill the vec beyond its capacity will cause a panic. /// * All of the vec's array slots are always initialized in terms of Rust's @@ -572,6 +572,7 @@ impl ArrayVec { } let target = &mut self.as_mut_slice()[index..]; + #[allow(clippy::needless_range_loop)] for i in 0..target.len() { core::mem::swap(&mut item, &mut target[i]); } @@ -1857,6 +1858,7 @@ impl ArrayVec { /// assert_eq!(v, &[1, 2, 3]); /// assert_eq!(v.capacity(), 13); /// ``` + #[inline] pub fn drain_to_vec_and_reserve(&mut self, n: usize) -> Vec { let cap = n + self.len(); let mut v = Vec::with_capacity(cap); @@ -1902,6 +1904,7 @@ impl ArrayVec { /// assert_eq!(v, &[1, 2, 3]); /// assert_eq!(v.capacity(), 3); /// ``` + #[inline] pub fn drain_to_vec(&mut self) -> Vec { self.drain_to_vec_and_reserve(0) } diff --git a/src/lib.rs b/src/lib.rs index 8970878..8ecd771 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ feature(debugger_visualizer), debugger_visualizer(natvis_file = "../debug_metadata/tinyvec.natvis") )] -#![cfg_attr(docs_rs, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] #![warn(clippy::missing_inline_in_public_items)] #![warn(clippy::must_use_candidate)] #![warn(missing_docs)] diff --git a/src/slicevec.rs b/src/slicevec.rs index 8856b53..90b8e9e 100644 --- a/src/slicevec.rs +++ b/src/slicevec.rs @@ -655,6 +655,7 @@ impl<'s, T> SliceVec<'s, T> { /// sv.push(13); /// assert_eq!(sv.grab_spare_slice().len(), 0); /// ``` + #[must_use] #[inline(always)] pub fn grab_spare_slice(&self) -> &[T] { &self.data[self.len..] diff --git a/src/tinyvec.rs b/src/tinyvec.rs index 974d0a8..953a47a 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -1,5 +1,3 @@ -#![cfg(feature = "alloc")] - use super::*; use alloc::vec::{self, Vec}; @@ -35,7 +33,7 @@ use serde::ser::{Serialize, SerializeSeq, Serializer}; /// let many_ints: TinyVec<[i32; 4]> = tiny_vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); /// ``` #[macro_export] -#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] macro_rules! tiny_vec { ($array_type:ty => $($elem:expr),* $(,)?) => { { @@ -94,7 +92,7 @@ pub enum TinyVecConstructor { /// let empty_tv = tiny_vec!([u8; 16]); /// let some_ints = tiny_vec!([i32; 4] => 1, 2, 3); /// ``` -#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub enum TinyVec { #[allow(missing_docs)] Inline(ArrayVec), @@ -266,6 +264,7 @@ impl TinyVec { /// tv.shrink_to_fit(); /// assert!(tv.is_inline()); /// ``` + #[inline] pub fn shrink_to_fit(&mut self) { let vec = match self { TinyVec::Inline(_) => return, @@ -276,7 +275,7 @@ impl TinyVec { return vec.shrink_to_fit(); } - let moved_vec = core::mem::replace(vec, Vec::new()); + let moved_vec = core::mem::take(vec); let mut av = ArrayVec::default(); let mut rest = av.fill(moved_vec); @@ -339,6 +338,7 @@ impl TinyVec { /// assert!(tv.is_heap()); /// assert!(tv.capacity() >= 35); /// ``` + #[inline] pub fn move_to_the_heap_and_reserve(&mut self, n: usize) { let arr = match self { TinyVec::Heap(h) => return h.reserve(n), @@ -388,6 +388,7 @@ impl TinyVec { /// assert!(tv.is_heap()); /// assert!(tv.capacity() >= 5); /// ``` + #[inline] pub fn reserve(&mut self, n: usize) { let arr = match self { TinyVec::Heap(h) => return h.reserve(n), @@ -451,6 +452,7 @@ impl TinyVec { /// assert!(tv.is_heap()); /// assert!(tv.capacity() >= 5); /// ``` + #[inline] pub fn reserve_exact(&mut self, n: usize) { let arr = match self { TinyVec::Heap(h) => return h.reserve_exact(n), @@ -640,7 +642,7 @@ impl TinyVec { /// assert_eq!(tv.as_slice(), &[2, 4][..]); /// ``` #[inline] - pub fn retain bool>(self: &mut Self, acceptable: F) { + pub fn retain bool>(&mut self, acceptable: F) { match self { TinyVec::Inline(i) => i.retain(acceptable), TinyVec::Heap(h) => h.retain(acceptable), @@ -671,14 +673,14 @@ impl TinyVec { /// Helper for getting the mut slice. #[inline(always)] #[must_use] - pub fn as_mut_slice(self: &mut Self) -> &mut [A::Item] { + pub fn as_mut_slice(&mut self) -> &mut [A::Item] { self.deref_mut() } /// Helper for getting the shared slice. #[inline(always)] #[must_use] - pub fn as_slice(self: &Self) -> &[A::Item] { + pub fn as_slice(&self) -> &[A::Item] { self.deref() } @@ -838,8 +840,7 @@ impl TinyVec { if let Some(x) = arr.try_insert(index, item) { let mut v = Vec::with_capacity(arr.len() * 2); - let mut it = - arr.iter_mut().map(|r| core::mem::replace(r, Default::default())); + let mut it = arr.iter_mut().map(core::mem::take); v.extend(it.by_ref().take(index)); v.push(x); v.extend(it); @@ -1061,7 +1062,7 @@ impl TinyVec { /// Draining iterator for `TinyVecDrain` /// /// See [`TinyVecDrain::drain`](TinyVecDrain::::drain) -#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub enum TinyVecDrain<'p, A: Array> { #[allow(missing_docs)] Inline(ArrayVecDrain<'p, A::Item>), @@ -1110,7 +1111,7 @@ impl<'p, A: Array> DoubleEndedIterator for TinyVecDrain<'p, A> { /// Splicing iterator for `TinyVec` /// See [`TinyVec::splice`](TinyVec::::splice) -#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub struct TinyVecSplice<'p, A: Array, I: Iterator> { parent: &'p mut TinyVec, removal_start: usize, @@ -1205,6 +1206,7 @@ where impl<'p, A: Array, I: Iterator> Drop for TinyVecSplice<'p, A, I> { + #[inline] fn drop(&mut self) { for _ in self.by_ref() {} @@ -1286,6 +1288,7 @@ impl From> for TinyVec { } impl From for TinyVec { + #[inline] fn from(array: A) -> Self { TinyVec::Inline(ArrayVec::from(array)) } @@ -1330,7 +1333,7 @@ impl FromIterator for TinyVec { } /// Iterator for consuming an `TinyVec` and returning owned elements. -#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub enum TinyVecIterator { #[allow(missing_docs)] Inline(ArrayVecIterator),