Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
os: [ubuntu-latest]
rust:
- 1.47.0
- 1.47.0 # approximate MSRV is Stable -30
- stable
- beta
- nightly
Expand Down
18 changes: 12 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions src/arrayvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -572,6 +572,7 @@ impl<A: Array> ArrayVec<A> {
}

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]);
}
Expand Down Expand Up @@ -1857,6 +1858,7 @@ impl<A: Array> ArrayVec<A> {
/// assert_eq!(v, &[1, 2, 3]);
/// assert_eq!(v.capacity(), 13);
/// ```
#[inline]
pub fn drain_to_vec_and_reserve(&mut self, n: usize) -> Vec<A::Item> {
let cap = n + self.len();
let mut v = Vec::with_capacity(cap);
Expand Down Expand Up @@ -1902,6 +1904,7 @@ impl<A: Array> ArrayVec<A> {
/// assert_eq!(v, &[1, 2, 3]);
/// assert_eq!(v.capacity(), 3);
/// ```
#[inline]
pub fn drain_to_vec(&mut self) -> Vec<A::Item> {
self.drain_to_vec_and_reserve(0)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions src/slicevec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..]
Expand Down
29 changes: 16 additions & 13 deletions src/tinyvec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature = "alloc")]

use super::*;

use alloc::vec::{self, Vec};
Expand Down Expand Up @@ -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),* $(,)?) => {
{
Expand Down Expand Up @@ -94,7 +92,7 @@ pub enum TinyVecConstructor<A: Array> {
/// 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<A: Array> {
#[allow(missing_docs)]
Inline(ArrayVec<A>),
Expand Down Expand Up @@ -266,6 +264,7 @@ impl<A: Array> TinyVec<A> {
/// tv.shrink_to_fit();
/// assert!(tv.is_inline());
/// ```
#[inline]
pub fn shrink_to_fit(&mut self) {
let vec = match self {
TinyVec::Inline(_) => return,
Expand All @@ -276,7 +275,7 @@ impl<A: Array> TinyVec<A> {
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);
Expand Down Expand Up @@ -339,6 +338,7 @@ impl<A: Array> TinyVec<A> {
/// 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),
Expand Down Expand Up @@ -388,6 +388,7 @@ impl<A: Array> TinyVec<A> {
/// 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),
Expand Down Expand Up @@ -451,6 +452,7 @@ impl<A: Array> TinyVec<A> {
/// 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),
Expand Down Expand Up @@ -640,7 +642,7 @@ impl<A: Array> TinyVec<A> {
/// assert_eq!(tv.as_slice(), &[2, 4][..]);
/// ```
#[inline]
pub fn retain<F: FnMut(&A::Item) -> bool>(self: &mut Self, acceptable: F) {
pub fn retain<F: FnMut(&A::Item) -> bool>(&mut self, acceptable: F) {
match self {
TinyVec::Inline(i) => i.retain(acceptable),
TinyVec::Heap(h) => h.retain(acceptable),
Expand Down Expand Up @@ -671,14 +673,14 @@ impl<A: Array> TinyVec<A> {
/// 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()
}

Expand Down Expand Up @@ -838,8 +840,7 @@ impl<A: Array> TinyVec<A> {

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);
Expand Down Expand Up @@ -1061,7 +1062,7 @@ impl<A: Array> TinyVec<A> {
/// Draining iterator for `TinyVecDrain`
///
/// See [`TinyVecDrain::drain`](TinyVecDrain::<A>::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>),
Expand Down Expand Up @@ -1110,7 +1111,7 @@ impl<'p, A: Array> DoubleEndedIterator for TinyVecDrain<'p, A> {

/// Splicing iterator for `TinyVec`
/// See [`TinyVec::splice`](TinyVec::<A>::splice)
#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub struct TinyVecSplice<'p, A: Array, I: Iterator<Item = A::Item>> {
parent: &'p mut TinyVec<A>,
removal_start: usize,
Expand Down Expand Up @@ -1205,6 +1206,7 @@ where
impl<'p, A: Array, I: Iterator<Item = A::Item>> Drop
for TinyVecSplice<'p, A, I>
{
#[inline]
fn drop(&mut self) {
for _ in self.by_ref() {}

Expand Down Expand Up @@ -1286,6 +1288,7 @@ impl<A: Array> From<ArrayVec<A>> for TinyVec<A> {
}

impl<A: Array> From<A> for TinyVec<A> {
#[inline]
fn from(array: A) -> Self {
TinyVec::Inline(ArrayVec::from(array))
}
Expand Down Expand Up @@ -1330,7 +1333,7 @@ impl<A: Array> FromIterator<A::Item> for TinyVec<A> {
}

/// 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<A: Array> {
#[allow(missing_docs)]
Inline(ArrayVecIterator<A>),
Expand Down
Loading