From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/tinyvec/src/array.rs | 48 + vendor/tinyvec/src/array/const_generic_impl.rs | 23 + vendor/tinyvec/src/array/generated_impl.rs | 9616 ++++++++++++++++++++++++ vendor/tinyvec/src/arrayvec.rs | 1873 +++++ vendor/tinyvec/src/arrayvec_drain.rs | 93 + vendor/tinyvec/src/lib.rs | 107 + vendor/tinyvec/src/slicevec.rs | 1080 +++ vendor/tinyvec/src/tinyvec.rs | 1740 +++++ 8 files changed, 14580 insertions(+) create mode 100644 vendor/tinyvec/src/array.rs create mode 100644 vendor/tinyvec/src/array/const_generic_impl.rs create mode 100644 vendor/tinyvec/src/array/generated_impl.rs create mode 100644 vendor/tinyvec/src/arrayvec.rs create mode 100644 vendor/tinyvec/src/arrayvec_drain.rs create mode 100644 vendor/tinyvec/src/lib.rs create mode 100644 vendor/tinyvec/src/slicevec.rs create mode 100644 vendor/tinyvec/src/tinyvec.rs (limited to 'vendor/tinyvec/src') diff --git a/vendor/tinyvec/src/array.rs b/vendor/tinyvec/src/array.rs new file mode 100644 index 000000000..cc84aaf74 --- /dev/null +++ b/vendor/tinyvec/src/array.rs @@ -0,0 +1,48 @@ +/// A trait for types that are an array. +/// +/// An "array", for our purposes, has the following properties: +/// * Owns some number of elements. +/// * The element type can be generic, but must implement [`Default`]. +/// * The capacity is fixed at compile time, based on the implementing type. +/// * You can get a shared or mutable slice to the elements. +/// +/// You are generally **not** expected to need to implement this yourself. It is +/// already implemented for all the major array lengths (`0..=32` and the powers +/// of 2 up to 4,096), or for all array lengths with the feature `rustc_1_55`. +/// +/// **Additional lengths can easily be added upon request.** +/// +/// ## Safety Reminder +/// +/// Just a reminder: this trait is 100% safe, which means that `unsafe` code +/// **must not** rely on an instance of this trait being correct. +pub trait Array { + /// The type of the items in the thing. + type Item: Default; + + /// The number of slots in the thing. + const CAPACITY: usize; + + /// Gives a shared slice over the whole thing. + /// + /// A correct implementation will return a slice with a length equal to the + /// `CAPACITY` value. + fn as_slice(&self) -> &[Self::Item]; + + /// Gives a unique slice over the whole thing. + /// + /// A correct implementation will return a slice with a length equal to the + /// `CAPACITY` value. + fn as_slice_mut(&mut self) -> &mut [Self::Item]; + + /// Create a default-initialized instance of ourself, similar to the + /// [`Default`] trait, but implemented for the same range of sizes as + /// [`Array`]. + fn default() -> Self; +} + +#[cfg(feature = "rustc_1_55")] +mod const_generic_impl; + +#[cfg(not(feature = "rustc_1_55"))] +mod generated_impl; diff --git a/vendor/tinyvec/src/array/const_generic_impl.rs b/vendor/tinyvec/src/array/const_generic_impl.rs new file mode 100644 index 000000000..0b145f168 --- /dev/null +++ b/vendor/tinyvec/src/array/const_generic_impl.rs @@ -0,0 +1,23 @@ +use super::Array; + +impl Array for [T; N] { + type Item = T; + const CAPACITY: usize = N; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [(); N].map(|_| Default::default()) + } +} diff --git a/vendor/tinyvec/src/array/generated_impl.rs b/vendor/tinyvec/src/array/generated_impl.rs new file mode 100644 index 000000000..d72169c5b --- /dev/null +++ b/vendor/tinyvec/src/array/generated_impl.rs @@ -0,0 +1,9616 @@ +// Generated file, to regenerate run +// ./gen-array-impls.sh > src/array/generated_impl.rs +// from the repo root + +use super::Array; + +impl Array for [T; 0] { + type Item = T; + const CAPACITY: usize = 0; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [] + } +} + +impl Array for [T; 1] { + type Item = T; + const CAPACITY: usize = 1; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [T::default()] + } +} + +impl Array for [T; 2] { + type Item = T; + const CAPACITY: usize = 2; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [T::default(), T::default()] + } +} + +impl Array for [T; 3] { + type Item = T; + const CAPACITY: usize = 3; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [T::default(), T::default(), T::default()] + } +} + +impl Array for [T; 4] { + type Item = T; + const CAPACITY: usize = 4; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [T::default(), T::default(), T::default(), T::default()] + } +} + +impl Array for [T; 5] { + type Item = T; + const CAPACITY: usize = 5; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [T::default(), T::default(), T::default(), T::default(), T::default()] + } +} + +impl Array for [T; 6] { + type Item = T; + const CAPACITY: usize = 6; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 7] { + type Item = T; + const CAPACITY: usize = 7; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 8] { + type Item = T; + const CAPACITY: usize = 8; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 9] { + type Item = T; + const CAPACITY: usize = 9; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 10] { + type Item = T; + const CAPACITY: usize = 10; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 11] { + type Item = T; + const CAPACITY: usize = 11; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 12] { + type Item = T; + const CAPACITY: usize = 12; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 13] { + type Item = T; + const CAPACITY: usize = 13; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 14] { + type Item = T; + const CAPACITY: usize = 14; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 15] { + type Item = T; + const CAPACITY: usize = 15; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 16] { + type Item = T; + const CAPACITY: usize = 16; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 17] { + type Item = T; + const CAPACITY: usize = 17; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 18] { + type Item = T; + const CAPACITY: usize = 18; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 19] { + type Item = T; + const CAPACITY: usize = 19; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 20] { + type Item = T; + const CAPACITY: usize = 20; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 21] { + type Item = T; + const CAPACITY: usize = 21; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 22] { + type Item = T; + const CAPACITY: usize = 22; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 23] { + type Item = T; + const CAPACITY: usize = 23; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 24] { + type Item = T; + const CAPACITY: usize = 24; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 25] { + type Item = T; + const CAPACITY: usize = 25; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 26] { + type Item = T; + const CAPACITY: usize = 26; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 27] { + type Item = T; + const CAPACITY: usize = 27; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 28] { + type Item = T; + const CAPACITY: usize = 28; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 29] { + type Item = T; + const CAPACITY: usize = 29; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 30] { + type Item = T; + const CAPACITY: usize = 30; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 31] { + type Item = T; + const CAPACITY: usize = 31; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 32] { + type Item = T; + const CAPACITY: usize = 32; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 33] { + type Item = T; + const CAPACITY: usize = 33; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 64] { + type Item = T; + const CAPACITY: usize = 64; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 128] { + type Item = T; + const CAPACITY: usize = 128; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 256] { + type Item = T; + const CAPACITY: usize = 256; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 512] { + type Item = T; + const CAPACITY: usize = 512; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 1024] { + type Item = T; + const CAPACITY: usize = 1024; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 2048] { + type Item = T; + const CAPACITY: usize = 2048; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} + +impl Array for [T; 4096] { + type Item = T; + const CAPACITY: usize = 4096; + + #[inline(always)] + #[must_use] + fn as_slice(&self) -> &[T] { + &*self + } + + #[inline(always)] + #[must_use] + fn as_slice_mut(&mut self) -> &mut [T] { + &mut *self + } + + #[inline(always)] + fn default() -> Self { + [ + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + T::default(), + ] + } +} diff --git a/vendor/tinyvec/src/arrayvec.rs b/vendor/tinyvec/src/arrayvec.rs new file mode 100644 index 000000000..9cfe58d8d --- /dev/null +++ b/vendor/tinyvec/src/arrayvec.rs @@ -0,0 +1,1873 @@ +use super::*; +use core::convert::{TryFrom, TryInto}; + +#[cfg(feature = "serde")] +use core::marker::PhantomData; +#[cfg(feature = "serde")] +use serde::de::{ + Deserialize, Deserializer, Error as DeserializeError, SeqAccess, Visitor, +}; +#[cfg(feature = "serde")] +use serde::ser::{Serialize, SerializeSeq, Serializer}; + +/// Helper to make an `ArrayVec`. +/// +/// You specify the backing array type, and optionally give all the elements you +/// want to initially place into the array. +/// +/// ```rust +/// use tinyvec::*; +/// +/// // The backing array type can be specified in the macro call +/// let empty_av = array_vec!([u8; 16]); +/// let some_ints = array_vec!([i32; 4] => 1, 2, 3); +/// +/// // Or left to inference +/// let empty_av: ArrayVec<[u8; 10]> = array_vec!(); +/// let some_ints: ArrayVec<[u8; 10]> = array_vec!(5, 6, 7, 8); +/// ``` +#[macro_export] +macro_rules! array_vec { + ($array_type:ty => $($elem:expr),* $(,)?) => { + { + let mut av: $crate::ArrayVec<$array_type> = Default::default(); + $( av.push($elem); )* + av + } + }; + ($array_type:ty) => { + $crate::ArrayVec::<$array_type>::default() + }; + ($($elem:expr),*) => { + $crate::array_vec!(_ => $($elem),*) + }; + ($elem:expr; $n:expr) => { + $crate::ArrayVec::from([$elem; $n]) + }; + () => { + $crate::array_vec!(_) + }; +} + +/// An array-backed, vector-like data structure. +/// +/// * `ArrayVec` has a fixed capacity, equal to the array size. +/// * `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 +/// memory model. When you remove a element from a location, the old value at +/// that location is replaced with the type's default value. +/// +/// The overall API of this type is intended to, as much as possible, emulate +/// the API of the [`Vec`](https://doc.rust-lang.org/alloc/vec/struct.Vec.html) +/// type. +/// +/// ## Construction +/// +/// You can use the `array_vec!` macro similarly to how you might use the `vec!` +/// macro. Specify the array type, then optionally give all the initial values +/// you want to have. +/// ```rust +/// # use tinyvec::*; +/// let some_ints = array_vec!([i32; 4] => 1, 2, 3); +/// assert_eq!(some_ints.len(), 3); +/// ``` +/// +/// The [`default`](ArrayVec::new) for an `ArrayVec` is to have a default +/// array with length 0. The [`new`](ArrayVec::new) method is the same as +/// calling `default` +/// ```rust +/// # use tinyvec::*; +/// let some_ints = ArrayVec::<[i32; 7]>::default(); +/// assert_eq!(some_ints.len(), 0); +/// +/// let more_ints = ArrayVec::<[i32; 7]>::new(); +/// assert_eq!(some_ints, more_ints); +/// ``` +/// +/// If you have an array and want the _whole thing_ so count as being "in" the +/// new `ArrayVec` you can use one of the `from` implementations. If you want +/// _part of_ the array then you can use +/// [`from_array_len`](ArrayVec::from_array_len): +/// ```rust +/// # use tinyvec::*; +/// let some_ints = ArrayVec::from([5, 6, 7, 8]); +/// assert_eq!(some_ints.len(), 4); +/// +/// let more_ints = ArrayVec::from_array_len([5, 6, 7, 8], 2); +/// assert_eq!(more_ints.len(), 2); +/// +/// let no_ints: ArrayVec<[u8; 5]> = ArrayVec::from_array_empty([1, 2, 3, 4, 5]); +/// assert_eq!(no_ints.len(), 0); +/// ``` +#[repr(C)] +pub struct ArrayVec { + len: u16, + pub(crate) data: A, +} + +impl Clone for ArrayVec +where + A: Array + Clone, + A::Item: Clone, +{ + #[inline] + fn clone(&self) -> Self { + Self { data: self.data.clone(), len: self.len } + } + + #[inline] + fn clone_from(&mut self, o: &Self) { + let iter = self + .data + .as_slice_mut() + .iter_mut() + .zip(o.data.as_slice()) + .take(self.len.max(o.len) as usize); + for (dst, src) in iter { + dst.clone_from(src) + } + if let Some(to_drop) = + self.data.as_slice_mut().get_mut((o.len as usize)..(self.len as usize)) + { + to_drop.iter_mut().for_each(|x| drop(take(x))); + } + self.len = o.len; + } +} + +impl Copy for ArrayVec +where + A: Array + Copy, + A::Item: Copy, +{ +} + +impl Default for ArrayVec { + fn default() -> Self { + Self { len: 0, data: A::default() } + } +} + +impl Deref for ArrayVec { + type Target = [A::Item]; + #[inline(always)] + #[must_use] + fn deref(&self) -> &Self::Target { + &self.data.as_slice()[..self.len as usize] + } +} + +impl DerefMut for ArrayVec { + #[inline(always)] + #[must_use] + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.data.as_slice_mut()[..self.len as usize] + } +} + +impl> Index for ArrayVec { + type Output = >::Output; + #[inline(always)] + #[must_use] + fn index(&self, index: I) -> &Self::Output { + &self.deref()[index] + } +} + +impl> IndexMut for ArrayVec { + #[inline(always)] + #[must_use] + fn index_mut(&mut self, index: I) -> &mut Self::Output { + &mut self.deref_mut()[index] + } +} + +#[cfg(feature = "serde")] +#[cfg_attr(docs_rs, doc(cfg(feature = "serde")))] +impl Serialize for ArrayVec +where + A::Item: Serialize, +{ + #[must_use] + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for element in self.iter() { + seq.serialize_element(element)?; + } + seq.end() + } +} + +#[cfg(feature = "serde")] +#[cfg_attr(docs_rs, doc(cfg(feature = "serde")))] +impl<'de, A: Array> Deserialize<'de> for ArrayVec +where + A::Item: Deserialize<'de>, +{ + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_seq(ArrayVecVisitor(PhantomData)) + } +} + +#[cfg(all(feature = "arbitrary", feature = "nightly_const_generics"))] +#[cfg_attr( + docs_rs, + doc(cfg(all(feature = "arbitrary", feature = "nightly_const_generics"))) +)] +impl<'a, T, const N: usize> arbitrary::Arbitrary<'a> for ArrayVec<[T; N]> +where + T: arbitrary::Arbitrary<'a> + Default, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let v = <[T; N]>::arbitrary(u)?; + let av = ArrayVec::from(v); + Ok(av) + } +} + +impl ArrayVec { + /// Move all values from `other` into this vec. + /// + /// ## Panics + /// * If the vec overflows its capacity + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 10] => 1, 2, 3); + /// let mut av2 = array_vec!([i32; 10] => 4, 5, 6); + /// av.append(&mut av2); + /// assert_eq!(av, &[1, 2, 3, 4, 5, 6][..]); + /// assert_eq!(av2, &[][..]); + /// ``` + #[inline] + pub fn append(&mut self, other: &mut Self) { + assert!( + self.try_append(other).is_none(), + "ArrayVec::append> total length {} exceeds capacity {}!", + self.len() + other.len(), + A::CAPACITY + ); + } + + /// Move all values from `other` into this vec. + /// If appending would overflow the capacity, Some(other) is returned. + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 7] => 1, 2, 3); + /// let mut av2 = array_vec!([i32; 7] => 4, 5, 6); + /// av.append(&mut av2); + /// assert_eq!(av, &[1, 2, 3, 4, 5, 6][..]); + /// assert_eq!(av2, &[][..]); + /// + /// let mut av3 = array_vec!([i32; 7] => 7, 8, 9); + /// assert!(av.try_append(&mut av3).is_some()); + /// assert_eq!(av, &[1, 2, 3, 4, 5, 6][..]); + /// assert_eq!(av3, &[7, 8, 9][..]); + /// ``` + #[inline] + pub fn try_append<'other>( + &mut self, other: &'other mut Self, + ) -> Option<&'other mut Self> { + let new_len = self.len() + other.len(); + if new_len > A::CAPACITY { + return Some(other); + } + + let iter = other.iter_mut().map(take); + for item in iter { + self.push(item); + } + + other.set_len(0); + + return None; + } + + /// A `*mut` pointer to the backing array. + /// + /// ## Safety + /// + /// This pointer has provenance over the _entire_ backing array. + #[inline(always)] + #[must_use] + pub fn as_mut_ptr(&mut self) -> *mut A::Item { + self.data.as_slice_mut().as_mut_ptr() + } + + /// Performs a `deref_mut`, into unique slice form. + #[inline(always)] + #[must_use] + pub fn as_mut_slice(&mut self) -> &mut [A::Item] { + self.deref_mut() + } + + /// A `*const` pointer to the backing array. + /// + /// ## Safety + /// + /// This pointer has provenance over the _entire_ backing array. + #[inline(always)] + #[must_use] + pub fn as_ptr(&self) -> *const A::Item { + self.data.as_slice().as_ptr() + } + + /// Performs a `deref`, into shared slice form. + #[inline(always)] + #[must_use] + pub fn as_slice(&self) -> &[A::Item] { + self.deref() + } + + /// The capacity of the `ArrayVec`. + /// + /// This is fixed based on the array type, but can't yet be made a `const fn` + /// on Stable Rust. + #[inline(always)] + #[must_use] + pub fn capacity(&self) -> usize { + // Note: This shouldn't use A::CAPACITY, because unsafe code can't rely on + // any Array invariants. This ensures that at the very least, the returned + // value is a valid length for a subslice of the backing array. + self.data.as_slice().len() + } + + /// Truncates the `ArrayVec` down to length 0. + #[inline(always)] + pub fn clear(&mut self) { + self.truncate(0) + } + + /// Creates a draining iterator that removes the specified range in the vector + /// and yields the removed items. + /// + /// ## Panics + /// * If the start is greater than the end + /// * If the end is past the edge of the vec. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 4] => 1, 2, 3); + /// let av2: ArrayVec<[i32; 4]> = av.drain(1..).collect(); + /// assert_eq!(av.as_slice(), &[1][..]); + /// assert_eq!(av2.as_slice(), &[2, 3][..]); + /// + /// av.drain(..); + /// assert_eq!(av.as_slice(), &[]); + /// ``` + #[inline] + pub fn drain(&mut self, range: R) -> ArrayVecDrain<'_, A::Item> + where + R: RangeBounds, + { + ArrayVecDrain::new(self, range) + } + + /// Returns the inner array of the `ArrayVec`. + /// + /// This returns the full array, even if the `ArrayVec` length is currently + /// less than that. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::{array_vec, ArrayVec}; + /// let mut favorite_numbers = array_vec!([i32; 5] => 87, 48, 33, 9, 26); + /// assert_eq!(favorite_numbers.clone().into_inner(), [87, 48, 33, 9, 26]); + /// + /// favorite_numbers.pop(); + /// assert_eq!(favorite_numbers.into_inner(), [87, 48, 33, 9, 0]); + /// ``` + /// + /// A use for this function is to build an array from an iterator by first + /// collecting it into an `ArrayVec`. + /// + /// ```rust + /// # use tinyvec::ArrayVec; + /// let arr_vec: ArrayVec<[i32; 10]> = (1..=3).cycle().take(10).collect(); + /// let inner = arr_vec.into_inner(); + /// assert_eq!(inner, [1, 2, 3, 1, 2, 3, 1, 2, 3, 1]); + /// ``` + #[inline] + pub fn into_inner(self) -> A { + self.data + } + + /// Clone each element of the slice into this `ArrayVec`. + /// + /// ## Panics + /// * If the `ArrayVec` would overflow, this will panic. + #[inline] + pub fn extend_from_slice(&mut self, sli: &[A::Item]) + where + A::Item: Clone, + { + if sli.is_empty() { + return; + } + + let new_len = self.len as usize + sli.len(); + assert!( + new_len <= A::CAPACITY, + "ArrayVec::extend_from_slice> total length {} exceeds capacity {}!", + new_len, + A::CAPACITY + ); + + let target = &mut self.data.as_slice_mut()[self.len as usize..new_len]; + target.clone_from_slice(sli); + self.set_len(new_len); + } + + /// Fill the vector until its capacity has been reached. + /// + /// Successively fills unused space in the spare slice of the vector with + /// elements from the iterator. It then returns the remaining iterator + /// without exhausting it. This also allows appending the head of an + /// infinite iterator. + /// + /// This is an alternative to `Extend::extend` method for cases where the + /// length of the iterator can not be checked. Since this vector can not + /// reallocate to increase its capacity, it is unclear what to do with + /// remaining elements in the iterator and the iterator itself. The + /// interface also provides no way to communicate this to the caller. + /// + /// ## Panics + /// * If the `next` method of the provided iterator panics. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 4]); + /// let mut to_inf = av.fill(0..); + /// assert_eq!(&av[..], [0, 1, 2, 3]); + /// assert_eq!(to_inf.next(), Some(4)); + /// ``` + #[inline] + pub fn fill>( + &mut self, iter: I, + ) -> I::IntoIter { + // If this is written as a call to push for each element in iter, the + // compiler emits code that updates the length for every element. The + // additional complexity from that length update is worth nearly 2x in + // the runtime of this function. + let mut iter = iter.into_iter(); + let mut pushed = 0; + let to_take = self.capacity() - self.len(); + let target = &mut self.data.as_slice_mut()[self.len as usize..]; + for element in iter.by_ref().take(to_take) { + target[pushed] = element; + pushed += 1; + } + self.len += pushed as u16; + iter + } + + /// Wraps up an array and uses the given length as the initial length. + /// + /// If you want to simply use the full array, use `from` instead. + /// + /// ## Panics + /// + /// * The length specified must be less than or equal to the capacity of the + /// array. + #[inline] + #[must_use] + #[allow(clippy::match_wild_err_arm)] + pub fn from_array_len(data: A, len: usize) -> Self { + match Self::try_from_array_len(data, len) { + Ok(out) => out, + Err(_) => panic!( + "ArrayVec::from_array_len> length {} exceeds capacity {}!", + len, + A::CAPACITY + ), + } + } + + /// Inserts an item at the position given, moving all following elements +1 + /// index. + /// + /// ## Panics + /// * If `index` > `len` + /// * If the capacity is exhausted + /// + /// ## Example + /// ```rust + /// use tinyvec::*; + /// let mut av = array_vec!([i32; 10] => 1, 2, 3); + /// av.insert(1, 4); + /// assert_eq!(av.as_slice(), &[1, 4, 2, 3]); + /// av.insert(4, 5); + /// assert_eq!(av.as_slice(), &[1, 4, 2, 3, 5]); + /// ``` + #[inline] + pub fn insert(&mut self, index: usize, item: A::Item) { + let x = self.try_insert(index, item); + assert!(x.is_none(), "ArrayVec::insert> capacity overflow!"); + } + + /// Tries to insert an item at the position given, moving all following + /// elements +1 index. + /// Returns back the element if the capacity is exhausted, + /// otherwise returns None. + /// + /// ## Panics + /// * If `index` > `len` + /// + /// ## Example + /// ```rust + /// use tinyvec::*; + /// let mut av = array_vec!([&'static str; 4] => "one", "two", "three"); + /// av.insert(1, "four"); + /// assert_eq!(av.as_slice(), &["one", "four", "two", "three"]); + /// assert_eq!(av.try_insert(4, "five"), Some("five")); + /// ``` + #[inline] + pub fn try_insert( + &mut self, index: usize, mut item: A::Item, + ) -> Option { + assert!( + index <= self.len as usize, + "ArrayVec::try_insert> index {} is out of bounds {}", + index, + self.len + ); + + // A previous implementation used self.try_push and slice::rotate_right + // rotate_right and rotate_left generate a huge amount of code and fail to + // inline; calling them here incurs the cost of all the cases they + // handle even though we're rotating a usually-small array by a constant + // 1 offset. This swap-based implementation benchmarks much better for + // small array lengths in particular. + + if (self.len as usize) < A::CAPACITY { + self.len += 1; + } else { + return Some(item); + } + + let target = &mut self.as_mut_slice()[index..]; + for i in 0..target.len() { + core::mem::swap(&mut item, &mut target[i]); + } + return None; + } + + /// Checks if the length is 0. + #[inline(always)] + #[must_use] + pub fn is_empty(&self) -> bool { + self.len == 0 + } + + /// The length of the `ArrayVec` (in elements). + #[inline(always)] + #[must_use] + pub fn len(&self) -> usize { + self.len as usize + } + + /// Makes a new, empty `ArrayVec`. + #[inline(always)] + #[must_use] + pub fn new() -> Self { + Self::default() + } + + /// Remove and return the last element of the vec, if there is one. + /// + /// ## Failure + /// * If the vec is empty you get `None`. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 10] => 1, 2); + /// assert_eq!(av.pop(), Some(2)); + /// assert_eq!(av.pop(), Some(1)); + /// assert_eq!(av.pop(), None); + /// ``` + #[inline] + pub fn pop(&mut self) -> Option { + if self.len > 0 { + self.len -= 1; + let out = take(&mut self.data.as_slice_mut()[self.len as usize]); + Some(out) + } else { + None + } + } + + /// Place an element onto the end of the vec. + /// + /// ## Panics + /// * If the length of the vec would overflow the capacity. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 2]); + /// assert_eq!(&av[..], []); + /// av.push(1); + /// assert_eq!(&av[..], [1]); + /// av.push(2); + /// assert_eq!(&av[..], [1, 2]); + /// // av.push(3); this would overflow the ArrayVec and panic! + /// ``` + #[inline(always)] + pub fn push(&mut self, val: A::Item) { + let x = self.try_push(val); + assert!(x.is_none(), "ArrayVec::push> capacity overflow!"); + } + + /// Tries to place an element onto the end of the vec.\ + /// Returns back the element if the capacity is exhausted, + /// otherwise returns None. + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 2]); + /// assert_eq!(av.as_slice(), []); + /// assert_eq!(av.try_push(1), None); + /// assert_eq!(&av[..], [1]); + /// assert_eq!(av.try_push(2), None); + /// assert_eq!(&av[..], [1, 2]); + /// assert_eq!(av.try_push(3), Some(3)); + /// ``` + #[inline(always)] + pub fn try_push(&mut self, val: A::Item) -> Option { + debug_assert!(self.len as usize <= A::CAPACITY); + + let itemref = match self.data.as_slice_mut().get_mut(self.len as usize) { + None => return Some(val), + Some(x) => x, + }; + + *itemref = val; + self.len += 1; + return None; + } + + /// Removes the item at `index`, shifting all others down by one index. + /// + /// Returns the removed element. + /// + /// ## Panics + /// + /// * If the index is out of bounds. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 4] => 1, 2, 3); + /// assert_eq!(av.remove(1), 2); + /// assert_eq!(&av[..], [1, 3]); + /// ``` + #[inline] + pub fn remove(&mut self, index: usize) -> A::Item { + let targets: &mut [A::Item] = &mut self.deref_mut()[index..]; + let item = take(&mut targets[0]); + + // A previous implementation used rotate_left + // rotate_right and rotate_left generate a huge amount of code and fail to + // inline; calling them here incurs the cost of all the cases they + // handle even though we're rotating a usually-small array by a constant + // 1 offset. This swap-based implementation benchmarks much better for + // small array lengths in particular. + + for i in 0..targets.len() - 1 { + targets.swap(i, i + 1); + } + self.len -= 1; + item + } + + /// As [`resize_with`](ArrayVec::resize_with) + /// and it clones the value as the closure. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// + /// let mut av = array_vec!([&str; 10] => "hello"); + /// av.resize(3, "world"); + /// assert_eq!(&av[..], ["hello", "world", "world"]); + /// + /// let mut av = array_vec!([i32; 10] => 1, 2, 3, 4); + /// av.resize(2, 0); + /// assert_eq!(&av[..], [1, 2]); + /// ``` + #[inline] + pub fn resize(&mut self, new_len: usize, new_val: A::Item) + where + A::Item: Clone, + { + self.resize_with(new_len, || new_val.clone()) + } + + /// Resize the vec to the new length. + /// + /// If it needs to be longer, it's filled with repeated calls to the provided + /// function. If it needs to be shorter, it's truncated. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// + /// let mut av = array_vec!([i32; 10] => 1, 2, 3); + /// av.resize_with(5, Default::default); + /// assert_eq!(&av[..], [1, 2, 3, 0, 0]); + /// + /// let mut av = array_vec!([i32; 10]); + /// let mut p = 1; + /// av.resize_with(4, || { + /// p *= 2; + /// p + /// }); + /// assert_eq!(&av[..], [2, 4, 8, 16]); + /// ``` + #[inline] + pub fn resize_with A::Item>( + &mut self, new_len: usize, mut f: F, + ) { + match new_len.checked_sub(self.len as usize) { + None => self.truncate(new_len), + Some(new_elements) => { + for _ in 0..new_elements { + self.push(f()); + } + } + } + } + + /// Walk the vec and keep only the elements that pass the predicate given. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// + /// let mut av = array_vec!([i32; 10] => 1, 1, 2, 3, 3, 4); + /// av.retain(|&x| x % 2 == 0); + /// assert_eq!(&av[..], [2, 4]); + /// ``` + #[inline] + pub fn retain bool>(&mut self, mut acceptable: F) { + // Drop guard to contain exactly the remaining elements when the test + // panics. + struct JoinOnDrop<'vec, Item> { + items: &'vec mut [Item], + done_end: usize, + // Start of tail relative to `done_end`. + tail_start: usize, + } + + impl Drop for JoinOnDrop<'_, Item> { + fn drop(&mut self) { + self.items[self.done_end..].rotate_left(self.tail_start); + } + } + + let mut rest = JoinOnDrop { + items: &mut self.data.as_slice_mut()[..self.len as usize], + done_end: 0, + tail_start: 0, + }; + + let len = self.len as usize; + for idx in 0..len { + // Loop start invariant: idx = rest.done_end + rest.tail_start + if !acceptable(&rest.items[idx]) { + let _ = take(&mut rest.items[idx]); + self.len -= 1; + rest.tail_start += 1; + } else { + rest.items.swap(rest.done_end, idx); + rest.done_end += 1; + } + } + } + + /// Forces the length of the vector to `new_len`. + /// + /// ## Panics + /// * If `new_len` is greater than the vec's capacity. + /// + /// ## Safety + /// * This is a fully safe operation! The inactive memory already counts as + /// "initialized" by Rust's rules. + /// * Other than "the memory is initialized" there are no other guarantees + /// regarding what you find in the inactive portion of the vec. + #[inline(always)] + pub fn set_len(&mut self, new_len: usize) { + if new_len > A::CAPACITY { + // Note(Lokathor): Technically we don't have to panic here, and we could + // just let some other call later on trigger a panic on accident when the + // length is wrong. However, it's a lot easier to catch bugs when things + // are more "fail-fast". + panic!( + "ArrayVec::set_len> new length {} exceeds capacity {}", + new_len, + A::CAPACITY + ) + } + + let new_len: u16 = new_len + .try_into() + .expect("ArrayVec::set_len> new length is not in range 0..=u16::MAX"); + self.len = new_len; + } + + /// Splits the collection at the point given. + /// + /// * `[0, at)` stays in this vec + /// * `[at, len)` ends up in the new vec. + /// + /// ## Panics + /// * if at > len + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 4] => 1, 2, 3); + /// let av2 = av.split_off(1); + /// assert_eq!(&av[..], [1]); + /// assert_eq!(&av2[..], [2, 3]); + /// ``` + #[inline] + pub fn split_off(&mut self, at: usize) -> Self { + // FIXME: should this just use drain into the output? + if at > self.len() { + panic!( + "ArrayVec::split_off> at value {} exceeds length of {}", + at, self.len + ); + } + let mut new = Self::default(); + let moves = &mut self.as_mut_slice()[at..]; + let split_len = moves.len(); + let targets = &mut new.data.as_slice_mut()[..split_len]; + moves.swap_with_slice(targets); + + /* moves.len() <= u16::MAX, so these are surely in u16 range */ + new.len = split_len as u16; + self.len = at as u16; + new + } + + /// Creates a splicing iterator that removes the specified range in the + /// vector, yields the removed items, and replaces them with elements from + /// the provided iterator. + /// + /// `splice` fuses the provided iterator, so elements after the first `None` + /// are ignored. + /// + /// ## Panics + /// * If the start is greater than the end. + /// * If the end is past the edge of the vec. + /// * If the provided iterator panics. + /// * If the new length would overflow the capacity of the array. Because + /// `ArrayVecSplice` adds elements to this vec in its destructor when + /// necessary, this panic would occur when it is dropped. + /// + /// ## Example + /// ```rust + /// use tinyvec::*; + /// let mut av = array_vec!([i32; 4] => 1, 2, 3); + /// let av2: ArrayVec<[i32; 4]> = av.splice(1.., 4..=6).collect(); + /// assert_eq!(av.as_slice(), &[1, 4, 5, 6][..]); + /// assert_eq!(av2.as_slice(), &[2, 3][..]); + /// + /// av.splice(.., None); + /// assert_eq!(av.as_slice(), &[]); + /// ``` + #[inline] + pub fn splice( + &mut self, range: R, replacement: I, + ) -> ArrayVecSplice<'_, A, core::iter::Fuse> + where + R: RangeBounds, + I: IntoIterator, + { + use core::ops::Bound; + let start = match range.start_bound() { + Bound::Included(x) => *x, + Bound::Excluded(x) => x.saturating_add(1), + Bound::Unbounded => 0, + }; + let end = match range.end_bound() { + Bound::Included(x) => x.saturating_add(1), + Bound::Excluded(x) => *x, + Bound::Unbounded => self.len(), + }; + assert!( + start <= end, + "ArrayVec::splice> Illegal range, {} to {}", + start, + end + ); + assert!( + end <= self.len(), + "ArrayVec::splice> Range ends at {} but length is only {}!", + end, + self.len() + ); + + ArrayVecSplice { + removal_start: start, + removal_end: end, + parent: self, + replacement: replacement.into_iter().fuse(), + } + } + + /// Remove an element, swapping the end of the vec into its place. + /// + /// ## Panics + /// * If the index is out of bounds. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([&str; 4] => "foo", "bar", "quack", "zap"); + /// + /// assert_eq!(av.swap_remove(1), "bar"); + /// assert_eq!(&av[..], ["foo", "zap", "quack"]); + /// + /// assert_eq!(av.swap_remove(0), "foo"); + /// assert_eq!(&av[..], ["quack", "zap"]); + /// ``` + #[inline] + pub fn swap_remove(&mut self, index: usize) -> A::Item { + assert!( + index < self.len(), + "ArrayVec::swap_remove> index {} is out of bounds {}", + index, + self.len + ); + if index == self.len() - 1 { + self.pop().unwrap() + } else { + let i = self.pop().unwrap(); + replace(&mut self[index], i) + } + } + + /// Reduces the vec's length to the given value. + /// + /// If the vec is already shorter than the input, nothing happens. + #[inline] + pub fn truncate(&mut self, new_len: usize) { + if new_len >= self.len as usize { + return; + } + + if needs_drop::() { + let len = self.len as usize; + self.data.as_slice_mut()[new_len..len] + .iter_mut() + .map(take) + .for_each(drop); + } + + /* new_len is less than self.len */ + self.len = new_len as u16; + } + + /// 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] + 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 { + Ok(Self { data, len: len as u16 }) + } else { + Err(data) + } + } +} + +impl ArrayVec { + /// Wraps up an array as a new empty `ArrayVec`. + /// + /// If you want to simply use the full array, use `from` instead. + /// + /// ## Examples + /// + /// This method in particular allows to create values for statics: + /// + /// ```rust + /// # use tinyvec::ArrayVec; + /// static DATA: ArrayVec<[u8; 5]> = ArrayVec::from_array_empty([0; 5]); + /// assert_eq!(DATA.len(), 0); + /// ``` + /// + /// But of course it is just an normal empty `ArrayVec`: + /// + /// ```rust + /// # use tinyvec::ArrayVec; + /// let mut data = ArrayVec::from_array_empty([1, 2, 3, 4]); + /// assert_eq!(&data[..], &[]); + /// data.push(42); + /// assert_eq!(&data[..], &[42]); + /// ``` + #[inline] + #[must_use] + pub const fn from_array_empty(data: A) -> Self { + Self { data, len: 0 } + } +} + +#[cfg(feature = "grab_spare_slice")] +impl ArrayVec { + /// Obtain the shared slice of the array _after_ the active memory. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 4]); + /// assert_eq!(av.grab_spare_slice().len(), 4); + /// av.push(10); + /// av.push(11); + /// av.push(12); + /// av.push(13); + /// assert_eq!(av.grab_spare_slice().len(), 0); + /// ``` + #[inline(always)] + pub fn grab_spare_slice(&self) -> &[A::Item] { + &self.data.as_slice()[self.len as usize..] + } + + /// Obtain the mutable slice of the array _after_ the active memory. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 4]); + /// assert_eq!(av.grab_spare_slice_mut().len(), 4); + /// av.push(10); + /// av.push(11); + /// assert_eq!(av.grab_spare_slice_mut().len(), 2); + /// ``` + #[inline(always)] + pub fn grab_spare_slice_mut(&mut self) -> &mut [A::Item] { + &mut self.data.as_slice_mut()[self.len as usize..] + } +} + +#[cfg(feature = "nightly_slice_partition_dedup")] +impl ArrayVec { + /// De-duplicates the vec contents. + #[inline(always)] + pub fn dedup(&mut self) + where + A::Item: PartialEq, + { + self.dedup_by(|a, b| a == b) + } + + /// De-duplicates the vec according to the predicate given. + #[inline(always)] + pub fn dedup_by(&mut self, same_bucket: F) + where + F: FnMut(&mut A::Item, &mut A::Item) -> bool, + { + let len = { + let (dedup, _) = self.as_mut_slice().partition_dedup_by(same_bucket); + dedup.len() + }; + self.truncate(len); + } + + /// De-duplicates the vec according to the key selector given. + #[inline(always)] + pub fn dedup_by_key(&mut self, mut key: F) + where + F: FnMut(&mut A::Item) -> K, + K: PartialEq, + { + self.dedup_by(|a, b| key(a) == key(b)) + } +} + +/// Splicing iterator for `ArrayVec` +/// See [`ArrayVec::splice`](ArrayVec::::splice) +pub struct ArrayVecSplice<'p, A: Array, I: Iterator> { + parent: &'p mut ArrayVec, + removal_start: usize, + removal_end: usize, + replacement: I, +} + +impl<'p, A: Array, I: Iterator> Iterator + for ArrayVecSplice<'p, A, I> +{ + type Item = A::Item; + + #[inline] + fn next(&mut self) -> Option { + if self.removal_start < self.removal_end { + match self.replacement.next() { + Some(replacement) => { + let removed = core::mem::replace( + &mut self.parent[self.removal_start], + replacement, + ); + self.removal_start += 1; + Some(removed) + } + None => { + let removed = self.parent.remove(self.removal_start); + self.removal_end -= 1; + Some(removed) + } + } + } else { + None + } + } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + let len = self.len(); + (len, Some(len)) + } +} + +impl<'p, A, I> ExactSizeIterator for ArrayVecSplice<'p, A, I> +where + A: Array, + I: Iterator, +{ + #[inline] + fn len(&self) -> usize { + self.removal_end - self.removal_start + } +} + +impl<'p, A, I> FusedIterator for ArrayVecSplice<'p, A, I> +where + A: Array, + I: Iterator, +{ +} + +impl<'p, A, I> DoubleEndedIterator for ArrayVecSplice<'p, A, I> +where + A: Array, + I: Iterator + DoubleEndedIterator, +{ + #[inline] + fn next_back(&mut self) -> Option { + if self.removal_start < self.removal_end { + match self.replacement.next_back() { + Some(replacement) => { + let removed = core::mem::replace( + &mut self.parent[self.removal_end - 1], + replacement, + ); + self.removal_end -= 1; + Some(removed) + } + None => { + let removed = self.parent.remove(self.removal_end - 1); + self.removal_end -= 1; + Some(removed) + } + } + } else { + None + } + } +} + +impl<'p, A: Array, I: Iterator> Drop + for ArrayVecSplice<'p, A, I> +{ + fn drop(&mut self) { + for _ in self.by_ref() {} + + // FIXME: reserve lower bound of size_hint + + for replacement in self.replacement.by_ref() { + self.parent.insert(self.removal_end, replacement); + self.removal_end += 1; + } + } +} + +impl AsMut<[A::Item]> for ArrayVec { + #[inline(always)] + #[must_use] + fn as_mut(&mut self) -> &mut [A::Item] { + &mut *self + } +} + +impl AsRef<[A::Item]> for ArrayVec { + #[inline(always)] + #[must_use] + fn as_ref(&self) -> &[A::Item] { + &*self + } +} + +impl Borrow<[A::Item]> for ArrayVec { + #[inline(always)] + #[must_use] + fn borrow(&self) -> &[A::Item] { + &*self + } +} + +impl BorrowMut<[A::Item]> for ArrayVec { + #[inline(always)] + #[must_use] + fn borrow_mut(&mut self) -> &mut [A::Item] { + &mut *self + } +} + +impl Extend for ArrayVec { + #[inline] + fn extend>(&mut self, iter: T) { + for t in iter { + self.push(t) + } + } +} + +impl From for ArrayVec { + #[inline(always)] + #[must_use] + /// The output has a length equal to the full array. + /// + /// If you want to select a length, use + /// [`from_array_len`](ArrayVec::from_array_len) + fn from(data: A) -> Self { + let len: u16 = data + .as_slice() + .len() + .try_into() + .expect("ArrayVec::from> length must be in range 0..=u16::MAX"); + Self { len, data } + } +} + +/// The error type returned when a conversion from a slice to an [`ArrayVec`] +/// fails. +#[derive(Debug, Copy, Clone)] +pub struct TryFromSliceError(()); + +impl core::fmt::Display for TryFromSliceError { + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { + f.write_str("could not convert slice to ArrayVec") + } +} + +#[cfg(feature = "std")] +impl std::error::Error for TryFromSliceError {} + +impl TryFrom<&'_ [T]> for ArrayVec +where + T: Clone + Default, + A: Array, +{ + type Error = TryFromSliceError; + + #[inline] + #[must_use] + /// The output has a length equal to that of the slice, with the same capacity + /// as `A`. + fn try_from(slice: &[T]) -> Result { + if slice.len() > A::CAPACITY { + Err(TryFromSliceError(())) + } else { + let mut arr = ArrayVec::new(); + // We do not use ArrayVec::extend_from_slice, because it looks like LLVM + // fails to deduplicate all the length-checking logic between the + // above if and the contents of that method, thus producing much + // slower code. Unlike many of the other optimizations in this + // crate, this one is worth keeping an eye on. I see no reason, for + // any element type, that these should produce different code. But + // they do. (rustc 1.51.0) + arr.set_len(slice.len()); + arr.as_mut_slice().clone_from_slice(slice); + Ok(arr) + } + } +} + +impl FromIterator for ArrayVec { + #[inline] + #[must_use] + fn from_iter>(iter: T) -> Self { + let mut av = Self::default(); + for i in iter { + av.push(i) + } + av + } +} + +/// Iterator for consuming an `ArrayVec` and returning owned elements. +pub struct ArrayVecIterator { + base: u16, + tail: u16, + data: A, +} + +impl ArrayVecIterator { + /// Returns the remaining items of this iterator as a slice. + #[inline] + #[must_use] + pub fn as_slice(&self) -> &[A::Item] { + &self.data.as_slice()[self.base as usize..self.tail as usize] + } +} +impl FusedIterator for ArrayVecIterator {} +impl Iterator for ArrayVecIterator { + type Item = A::Item; + #[inline] + fn next(&mut self) -> Option { + let slice = + &mut self.data.as_slice_mut()[self.base as usize..self.tail as usize]; + let itemref = slice.first_mut()?; + self.base += 1; + return Some(take(itemref)); + } + #[inline(always)] + #[must_use] + fn size_hint(&self) -> (usize, Option) { + let s = self.tail - self.base; + let s = s as usize; + (s, Some(s)) + } + #[inline(always)] + fn count(self) -> usize { + self.size_hint().0 + } + #[inline] + fn last(mut self) -> Option { + self.next_back() + } + #[inline] + fn nth(&mut self, n: usize) -> Option { + let slice = &mut self.data.as_slice_mut(); + let slice = &mut slice[self.base as usize..self.tail as usize]; + + if let Some(x) = slice.get_mut(n) { + /* n is in range [0 .. self.tail - self.base) so in u16 range */ + self.base += n as u16 + 1; + return Some(take(x)); + } + + self.base = self.tail; + return None; + } +} + +impl DoubleEndedIterator for ArrayVecIterator { + #[inline] + fn next_back(&mut self) -> Option { + let slice = + &mut self.data.as_slice_mut()[self.base as usize..self.tail as usize]; + let item = slice.last_mut()?; + self.tail -= 1; + return Some(take(item)); + } + #[cfg(feature = "rustc_1_40")] + #[inline] + fn nth_back(&mut self, n: usize) -> Option { + let base = self.base as usize; + let tail = self.tail as usize; + let slice = &mut self.data.as_slice_mut()[base..tail]; + let n = n.saturating_add(1); + + if let Some(n) = slice.len().checked_sub(n) { + let item = &mut slice[n]; + /* n is in [0..self.tail - self.base] range, so in u16 range */ + self.tail = self.base + n as u16; + return Some(take(item)); + } + + self.tail = self.base; + return None; + } +} + +impl Debug for ArrayVecIterator +where + A::Item: Debug, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { + f.debug_tuple("ArrayVecIterator").field(&self.as_slice()).finish() + } +} + +impl IntoIterator for ArrayVec { + type Item = A::Item; + type IntoIter = ArrayVecIterator; + #[inline(always)] + #[must_use] + fn into_iter(self) -> Self::IntoIter { + ArrayVecIterator { base: 0, tail: self.len, data: self.data } + } +} + +impl<'a, A: Array> IntoIterator for &'a mut ArrayVec { + type Item = &'a mut A::Item; + type IntoIter = core::slice::IterMut<'a, A::Item>; + #[inline(always)] + #[must_use] + fn into_iter(self) -> Self::IntoIter { + self.iter_mut() + } +} + +impl<'a, A: Array> IntoIterator for &'a ArrayVec { + type Item = &'a A::Item; + type IntoIter = core::slice::Iter<'a, A::Item>; + #[inline(always)] + #[must_use] + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +impl PartialEq for ArrayVec +where + A::Item: PartialEq, +{ + #[inline] + #[must_use] + fn eq(&self, other: &Self) -> bool { + self.as_slice().eq(other.as_slice()) + } +} +impl Eq for ArrayVec where A::Item: Eq {} + +impl PartialOrd for ArrayVec +where + A::Item: PartialOrd, +{ + #[inline] + #[must_use] + fn partial_cmp(&self, other: &Self) -> Option { + self.as_slice().partial_cmp(other.as_slice()) + } +} +impl Ord for ArrayVec +where + A::Item: Ord, +{ + #[inline] + #[must_use] + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.as_slice().cmp(other.as_slice()) + } +} + +impl PartialEq<&A> for ArrayVec +where + A::Item: PartialEq, +{ + #[inline] + #[must_use] + fn eq(&self, other: &&A) -> bool { + self.as_slice().eq(other.as_slice()) + } +} + +impl PartialEq<&[A::Item]> for ArrayVec +where + A::Item: PartialEq, +{ + #[inline] + #[must_use] + fn eq(&self, other: &&[A::Item]) -> bool { + self.as_slice().eq(*other) + } +} + +impl Hash for ArrayVec +where + A::Item: Hash, +{ + #[inline] + fn hash(&self, state: &mut H) { + self.as_slice().hash(state) + } +} + +#[cfg(feature = "experimental_write_impl")] +impl> core::fmt::Write for ArrayVec { + fn write_str(&mut self, s: &str) -> core::fmt::Result { + let my_len = self.len(); + let str_len = s.as_bytes().len(); + if my_len + str_len <= A::CAPACITY { + let remainder = &mut self.data.as_slice_mut()[my_len..]; + let target = &mut remainder[..str_len]; + target.copy_from_slice(s.as_bytes()); + Ok(()) + } else { + Err(core::fmt::Error) + } + } +} + +// // // // // // // // +// Formatting impls +// // // // // // // // + +impl Binary for ArrayVec +where + A::Item: Binary, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Binary::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl Debug for ArrayVec +where + A::Item: Debug, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Debug::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl Display for ArrayVec +where + A::Item: Display, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Display::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl LowerExp for ArrayVec +where + A::Item: LowerExp, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + LowerExp::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl LowerHex for ArrayVec +where + A::Item: LowerHex, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + LowerHex::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl Octal for ArrayVec +where + A::Item: Octal, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Octal::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl Pointer for ArrayVec +where + A::Item: Pointer, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Pointer::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl UpperExp for ArrayVec +where + A::Item: UpperExp, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + UpperExp::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl UpperHex for ArrayVec +where + A::Item: UpperHex, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + UpperHex::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +#[cfg(feature = "alloc")] +use alloc::vec::Vec; + +#[cfg(all(feature = "alloc", feature = "rustc_1_57"))] +use alloc::collections::TryReserveError; + +#[cfg(feature = "alloc")] +impl ArrayVec { + /// Drains all elements to a Vec, but reserves additional space + /// ``` + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 7] => 1, 2, 3); + /// let v = av.drain_to_vec_and_reserve(10); + /// assert_eq!(v, &[1, 2, 3]); + /// assert_eq!(v.capacity(), 13); + /// ``` + pub fn drain_to_vec_and_reserve(&mut self, n: usize) -> Vec { + let cap = n + self.len(); + let mut v = Vec::with_capacity(cap); + let iter = self.iter_mut().map(take); + v.extend(iter); + self.set_len(0); + return v; + } + + /// Tries to drain all elements to a Vec, but reserves additional space. + /// + /// # Errors + /// + /// If the allocator reports a failure, then an error is returned. + /// + /// ``` + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 7] => 1, 2, 3); + /// let v = av.try_drain_to_vec_and_reserve(10); + /// assert!(matches!(v, Ok(_))); + /// let v = v.unwrap(); + /// assert_eq!(v, &[1, 2, 3]); + /// assert_eq!(v.capacity(), 13); + /// ``` + #[cfg(feature = "rustc_1_57")] + pub fn try_drain_to_vec_and_reserve( + &mut self, n: usize, + ) -> Result, TryReserveError> { + let cap = n + self.len(); + let mut v = Vec::new(); + v.try_reserve(cap)?; + let iter = self.iter_mut().map(take); + v.extend(iter); + self.set_len(0); + return Ok(v); + } + + /// Drains all elements to a Vec + /// ``` + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 7] => 1, 2, 3); + /// let v = av.drain_to_vec(); + /// assert_eq!(v, &[1, 2, 3]); + /// assert_eq!(v.capacity(), 3); + /// ``` + pub fn drain_to_vec(&mut self) -> Vec { + self.drain_to_vec_and_reserve(0) + } + + /// Tries to drain all elements to a Vec. + /// + /// # Errors + /// + /// If the allocator reports a failure, then an error is returned. + /// + /// ``` + /// # use tinyvec::*; + /// let mut av = array_vec!([i32; 7] => 1, 2, 3); + /// let v = av.try_drain_to_vec(); + /// assert!(matches!(v, Ok(_))); + /// let v = v.unwrap(); + /// assert_eq!(v, &[1, 2, 3]); + /// // Vec may reserve more than necessary in order to prevent more future allocations. + /// assert!(v.capacity() >= 3); + /// ``` + #[cfg(feature = "rustc_1_57")] + pub fn try_drain_to_vec(&mut self) -> Result, TryReserveError> { + self.try_drain_to_vec_and_reserve(0) + } +} + +#[cfg(feature = "serde")] +struct ArrayVecVisitor(PhantomData); + +#[cfg(feature = "serde")] +impl<'de, A: Array> Visitor<'de> for ArrayVecVisitor +where + A::Item: Deserialize<'de>, +{ + type Value = ArrayVec; + + fn expecting( + &self, formatter: &mut core::fmt::Formatter, + ) -> core::fmt::Result { + formatter.write_str("a sequence") + } + + fn visit_seq(self, mut seq: S) -> Result + where + S: SeqAccess<'de>, + { + let mut new_arrayvec: ArrayVec = Default::default(); + + let mut idx = 0usize; + while let Some(value) = seq.next_element()? { + if new_arrayvec.len() >= new_arrayvec.capacity() { + return Err(DeserializeError::invalid_length(idx, &self)); + } + new_arrayvec.push(value); + idx = idx + 1; + } + + Ok(new_arrayvec) + } +} diff --git a/vendor/tinyvec/src/arrayvec_drain.rs b/vendor/tinyvec/src/arrayvec_drain.rs new file mode 100644 index 000000000..44133ecd0 --- /dev/null +++ b/vendor/tinyvec/src/arrayvec_drain.rs @@ -0,0 +1,93 @@ +use super::*; + +use core::{ + ops::{Bound, RangeBounds}, + slice, +}; + +/// Draining iterator for [`ArrayVec`] +/// +/// See [`ArrayVec::drain`](ArrayVec::drain) +pub struct ArrayVecDrain<'a, T: 'a + Default> { + iter: slice::IterMut<'a, T>, +} + +impl<'a, T: 'a + Default> ArrayVecDrain<'a, T> { + pub(crate) fn new(arr: &'a mut ArrayVec, range: R) -> Self + where + A: Array, + R: RangeBounds, + { + let start = match range.start_bound() { + Bound::Unbounded => 0, + Bound::Included(&n) => n, + Bound::Excluded(&n) => n.saturating_add(1), + }; + let end = match range.end_bound() { + Bound::Unbounded => arr.len(), + Bound::Included(&n) => n.saturating_add(1), + Bound::Excluded(&n) => n, + }; + + assert!( + start <= end, + "ArrayVec::drain> Illegal range, {} to {}", + start, + end + ); + assert!( + end <= arr.len(), + "ArrayVec::drain> Range ends at {}, but length is only {}", + end, + arr.len() + ); + + let len = end - start; + let to_rotate = &mut arr[start..]; + to_rotate.rotate_left(len); + + let oldlen = arr.len(); + let newlen = oldlen - len; + arr.set_len(newlen); + let slice = &mut arr.data.as_slice_mut()[newlen..oldlen]; + let iter = slice.iter_mut(); + Self { iter } + } +} + +impl<'a, T: 'a + Default> DoubleEndedIterator for ArrayVecDrain<'a, T> { + fn next_back(&mut self) -> Option { + self.iter.next_back().map(take) + } + + #[cfg(feature = "rustc_1_40")] + fn nth_back(&mut self, n: usize) -> Option { + self.iter.nth_back(n).map(take) + } +} + +impl<'a, T: 'a + Default> Iterator for ArrayVecDrain<'a, T> { + type Item = T; + fn next(&mut self) -> Option { + self.iter.next().map(take) + } + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } + fn nth(&mut self, n: usize) -> Option { + self.iter.nth(n).map(take) + } + fn last(self) -> Option { + self.iter.last().map(take) + } + fn for_each(self, f: F) + where + F: FnMut(Self::Item), + { + self.iter.map(take).for_each(f) + } +} + +impl<'a, T: 'a + Default> FusedIterator for ArrayVecDrain<'a, T> {} +impl<'a, T: 'a + Default> ExactSizeIterator for ArrayVecDrain<'a, T> {} +/* No need to impl Drop! */ diff --git a/vendor/tinyvec/src/lib.rs b/vendor/tinyvec/src/lib.rs new file mode 100644 index 000000000..87d96bb99 --- /dev/null +++ b/vendor/tinyvec/src/lib.rs @@ -0,0 +1,107 @@ +#![cfg_attr(not(feature = "std"), no_std)] +#![forbid(unsafe_code)] +#![cfg_attr( + feature = "nightly_slice_partition_dedup", + feature(slice_partition_dedup) +)] +#![cfg_attr(docs_rs, feature(doc_cfg))] +#![warn(clippy::missing_inline_in_public_items)] +#![warn(clippy::must_use_candidate)] +#![warn(missing_docs)] + +//! `tinyvec` provides 100% safe vec-like data structures. +//! +//! ## Provided Types +//! With no features enabled, this crate provides the [`ArrayVec`] type, which +//! is an array-backed storage. You can push values into the array and pop them +//! out of the array and so on. If the array is made to overflow it will panic. +//! +//! Similarly, there is also a [`SliceVec`] type available, which is a vec-like +//! that's backed by a slice you provide. You can add and remove elements, but +//! if you overflow the slice it will panic. +//! +//! With the `alloc` feature enabled, the crate also has a [`TinyVec`] type. +//! This is an enum type which is either an `Inline(ArrayVec)` or a `Heap(Vec)`. +//! If a `TinyVec` is `Inline` and would overflow it automatically transitions +//! itself into being `Heap` mode instead of a panic. +//! +//! All of this is done with no `unsafe` code within the crate. Technically the +//! `Vec` type from the standard library uses `unsafe` internally, but *this +//! crate* introduces no new `unsafe` code into your project. +//! +//! The limitation is that the element type of a vec from this crate must +//! support the [`Default`] trait. This means that this crate isn't suitable for +//! all situations, but a very surprising number of types do support `Default`. +//! +//! ## Other Features +//! * `grab_spare_slice` lets you get access to the "inactive" portions of an +//! ArrayVec. +//! * `rustc_1_40` makes the crate assume a minimum rust version of `1.40.0`, +//! which allows some better internal optimizations. +//! * `serde` provides a `Serialize` and `Deserialize` implementation for +//! [`TinyVec`] and [`ArrayVec`] types, provided the inner item also has an +//! implementation. +//! +//! ## API +//! The general goal of the crate is that, as much as possible, the vecs here +//! should be a "drop in" replacement for the standard library `Vec` type. We +//! strive to provide all of the `Vec` methods with the same names and +//! signatures. The exception is that the element type of some methods will have +//! a `Default` bound that's not part of the normal `Vec` type. +//! +//! The vecs here also have a few additional methods that aren't on the `Vec` +//! type. In this case, the names tend to be fairly long so that they are +//! unlikely to clash with any future methods added to `Vec`. +//! +//! ## Stability +//! * The `1.0` series of the crate works with Rustc `1.34.0` or later, though +//! you still need to have Rustc `1.36.0` to use the `alloc` feature. +//! * The `2.0` version of the crate is planned for some time after the +//! `min_const_generics` stuff becomes stable. This would greatly raise the +//! minimum rust version and also allow us to totally eliminate the need for +//! the `Array` trait. The actual usage of the crate is not expected to break +//! significantly in this transition. + +#[allow(unused_imports)] +use core::{ + borrow::{Borrow, BorrowMut}, + cmp::PartialEq, + convert::AsMut, + default::Default, + fmt::{ + Binary, Debug, Display, Formatter, LowerExp, LowerHex, Octal, Pointer, + UpperExp, UpperHex, + }, + hash::{Hash, Hasher}, + iter::{Extend, FromIterator, FusedIterator, IntoIterator, Iterator}, + mem::{needs_drop, replace}, + ops::{Deref, DerefMut, Index, IndexMut, RangeBounds}, + slice::SliceIndex, +}; + +#[cfg(feature = "alloc")] +#[doc(hidden)] // re-export for macros +pub extern crate alloc; + +mod array; +pub use array::*; + +mod arrayvec; +pub use arrayvec::*; + +mod arrayvec_drain; +pub use arrayvec_drain::*; + +mod slicevec; +pub use slicevec::*; + +#[cfg(feature = "alloc")] +mod tinyvec; +#[cfg(feature = "alloc")] +pub use crate::tinyvec::*; + +// TODO MSRV(1.40.0): Just call the normal `core::mem::take` +#[inline(always)] +fn take(from: &mut T) -> T { + replace(from, T::default()) +} diff --git a/vendor/tinyvec/src/slicevec.rs b/vendor/tinyvec/src/slicevec.rs new file mode 100644 index 000000000..11664e1e9 --- /dev/null +++ b/vendor/tinyvec/src/slicevec.rs @@ -0,0 +1,1080 @@ +#![allow(unused_variables)] +#![allow(missing_docs)] + +use super::*; + +/// A slice-backed vector-like data structure. +/// +/// This is a very similar concept to `ArrayVec`, but instead +/// of the backing memory being an owned array, the backing +/// memory is a unique-borrowed slice. You can thus create +/// one of these structures "around" some slice that you're +/// working with to make it easier to manipulate. +/// +/// * Has a fixed capacity (the initial slice size). +/// * Has a variable length. +pub struct SliceVec<'s, T> { + data: &'s mut [T], + len: usize, +} + +impl<'s, T> Default for SliceVec<'s, T> { + #[inline(always)] + #[must_use] + fn default() -> Self { + Self { data: &mut [], len: 0 } + } +} + +impl<'s, T> Deref for SliceVec<'s, T> { + type Target = [T]; + #[inline(always)] + #[must_use] + fn deref(&self) -> &Self::Target { + &self.data[..self.len] + } +} + +impl<'s, T> DerefMut for SliceVec<'s, T> { + #[inline(always)] + #[must_use] + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.data[..self.len] + } +} + +impl<'s, T, I> Index for SliceVec<'s, T> +where + I: SliceIndex<[T]>, +{ + type Output = >::Output; + #[inline(always)] + #[must_use] + fn index(&self, index: I) -> &Self::Output { + &self.deref()[index] + } +} + +impl<'s, T, I> IndexMut for SliceVec<'s, T> +where + I: SliceIndex<[T]>, +{ + #[inline(always)] + #[must_use] + fn index_mut(&mut self, index: I) -> &mut Self::Output { + &mut self.deref_mut()[index] + } +} + +impl<'s, T> SliceVec<'s, T> { + #[inline] + pub fn append(&mut self, other: &mut Self) + where + T: Default, + { + for item in other.drain(..) { + self.push(item) + } + } + + /// A `*mut` pointer to the backing slice. + /// + /// ## Safety + /// + /// This pointer has provenance over the _entire_ backing slice. + #[inline(always)] + #[must_use] + pub fn as_mut_ptr(&mut self) -> *mut T { + self.data.as_mut_ptr() + } + + /// Performs a `deref_mut`, into unique slice form. + #[inline(always)] + #[must_use] + pub fn as_mut_slice(&mut self) -> &mut [T] { + self.deref_mut() + } + + /// A `*const` pointer to the backing slice. + /// + /// ## Safety + /// + /// This pointer has provenance over the _entire_ backing slice. + #[inline(always)] + #[must_use] + pub fn as_ptr(&self) -> *const T { + self.data.as_ptr() + } + + /// Performs a `deref`, into shared slice form. + #[inline(always)] + #[must_use] + pub fn as_slice(&self) -> &[T] { + self.deref() + } + + /// The capacity of the `SliceVec`. + /// + /// This the length of the initial backing slice. + #[inline(always)] + #[must_use] + pub fn capacity(&self) -> usize { + self.data.len() + } + + /// Truncates the `SliceVec` down to length 0. + #[inline(always)] + pub fn clear(&mut self) + where + T: Default, + { + self.truncate(0) + } + + /// Creates a draining iterator that removes the specified range in the vector + /// and yields the removed items. + /// + /// ## Panics + /// * If the start is greater than the end + /// * If the end is past the edge of the vec. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [6, 7, 8]; + /// let mut sv = SliceVec::from(&mut arr); + /// let drained_values: ArrayVec<[i32; 4]> = sv.drain(1..).collect(); + /// assert_eq!(sv.as_slice(), &[6][..]); + /// assert_eq!(drained_values.as_slice(), &[7, 8][..]); + /// + /// sv.drain(..); + /// assert_eq!(sv.as_slice(), &[]); + /// ``` + #[inline] + pub fn drain<'p, R: RangeBounds>( + &'p mut self, range: R, + ) -> SliceVecDrain<'p, 's, T> + where + T: Default, + { + use core::ops::Bound; + let start = match range.start_bound() { + Bound::Included(x) => *x, + Bound::Excluded(x) => x.saturating_add(1), + Bound::Unbounded => 0, + }; + let end = match range.end_bound() { + Bound::Included(x) => x.saturating_add(1), + Bound::Excluded(x) => *x, + Bound::Unbounded => self.len, + }; + assert!( + start <= end, + "SliceVec::drain> Illegal range, {} to {}", + start, + end + ); + assert!( + end <= self.len, + "SliceVec::drain> Range ends at {} but length is only {}!", + end, + self.len + ); + SliceVecDrain { + parent: self, + target_start: start, + target_index: start, + target_end: end, + } + } + + #[inline] + pub fn extend_from_slice(&mut self, sli: &[T]) + where + T: Clone, + { + if sli.is_empty() { + return; + } + + let new_len = self.len + sli.len(); + if new_len > self.capacity() { + panic!( + "SliceVec::extend_from_slice> total length {} exceeds capacity {}", + new_len, + self.capacity() + ) + } + + let target = &mut self.data[self.len..new_len]; + target.clone_from_slice(sli); + self.set_len(new_len); + } + + /// Fill the vector until its capacity has been reached. + /// + /// Successively fills unused space in the spare slice of the vector with + /// elements from the iterator. It then returns the remaining iterator + /// without exhausting it. This also allows appending the head of an + /// infinite iterator. + /// + /// This is an alternative to `Extend::extend` method for cases where the + /// length of the iterator can not be checked. Since this vector can not + /// reallocate to increase its capacity, it is unclear what to do with + /// remaining elements in the iterator and the iterator itself. The + /// interface also provides no way to communicate this to the caller. + /// + /// ## Panics + /// * If the `next` method of the provided iterator panics. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [7, 7, 7, 7]; + /// let mut sv = SliceVec::from_slice_len(&mut arr, 0); + /// let mut to_inf = sv.fill(0..); + /// assert_eq!(&sv[..], [0, 1, 2, 3]); + /// assert_eq!(to_inf.next(), Some(4)); + /// ``` + #[inline] + pub fn fill>(&mut self, iter: I) -> I::IntoIter { + let mut iter = iter.into_iter(); + for element in iter.by_ref().take(self.capacity() - self.len()) { + self.push(element); + } + iter + } + + /// Wraps up a slice and uses the given length as the initial length. + /// + /// If you want to simply use the full slice, use `from` instead. + /// + /// ## Panics + /// + /// * The length specified must be less than or equal to the capacity of the + /// slice. + #[inline] + #[must_use] + #[allow(clippy::match_wild_err_arm)] + pub fn from_slice_len(data: &'s mut [T], len: usize) -> Self { + assert!(len <= data.len()); + Self { data, len } + } + + /// Inserts an item at the position given, moving all following elements +1 + /// index. + /// + /// ## Panics + /// * If `index` > `len` + /// * If the capacity is exhausted + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [1, 2, 3, 0, 0]; + /// let mut sv = SliceVec::from_slice_len(&mut arr, 3); + /// sv.insert(1, 4); + /// assert_eq!(sv.as_slice(), &[1, 4, 2, 3]); + /// sv.insert(4, 5); + /// assert_eq!(sv.as_slice(), &[1, 4, 2, 3, 5]); + /// ``` + #[inline] + pub fn insert(&mut self, index: usize, item: T) { + if index > self.len { + panic!("SliceVec::insert> index {} is out of bounds {}", index, self.len); + } + + // Try to push the element. + self.push(item); + // And move it into its place. + self.as_mut_slice()[index..].rotate_right(1); + } + + /// Checks if the length is 0. + #[inline(always)] + #[must_use] + pub fn is_empty(&self) -> bool { + self.len == 0 + } + + /// The length of the `SliceVec` (in elements). + #[inline(always)] + #[must_use] + pub fn len(&self) -> usize { + self.len + } + + /// Remove and return the last element of the vec, if there is one. + /// + /// ## Failure + /// * If the vec is empty you get `None`. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [1, 2]; + /// let mut sv = SliceVec::from(&mut arr); + /// assert_eq!(sv.pop(), Some(2)); + /// assert_eq!(sv.pop(), Some(1)); + /// assert_eq!(sv.pop(), None); + /// ``` + #[inline] + pub fn pop(&mut self) -> Option + where + T: Default, + { + if self.len > 0 { + self.len -= 1; + let out = take(&mut self.data[self.len]); + Some(out) + } else { + None + } + } + + /// Place an element onto the end of the vec. + /// + /// ## Panics + /// * If the length of the vec would overflow the capacity. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [0, 0]; + /// let mut sv = SliceVec::from_slice_len(&mut arr, 0); + /// assert_eq!(&sv[..], []); + /// sv.push(1); + /// assert_eq!(&sv[..], [1]); + /// sv.push(2); + /// assert_eq!(&sv[..], [1, 2]); + /// // sv.push(3); this would overflow the ArrayVec and panic! + /// ``` + #[inline(always)] + pub fn push(&mut self, val: T) { + if self.len < self.capacity() { + self.data[self.len] = val; + self.len += 1; + } else { + panic!("SliceVec::push> capacity overflow") + } + } + + /// Removes the item at `index`, shifting all others down by one index. + /// + /// Returns the removed element. + /// + /// ## Panics + /// + /// * If the index is out of bounds. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [1, 2, 3]; + /// let mut sv = SliceVec::from(&mut arr); + /// assert_eq!(sv.remove(1), 2); + /// assert_eq!(&sv[..], [1, 3]); + /// ``` + #[inline] + pub fn remove(&mut self, index: usize) -> T + where + T: Default, + { + let targets: &mut [T] = &mut self.deref_mut()[index..]; + let item = take(&mut targets[0]); + targets.rotate_left(1); + self.len -= 1; + item + } + + /// As [`resize_with`](SliceVec::resize_with) + /// and it clones the value as the closure. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// // bigger + /// let mut arr = ["hello", "", "", "", ""]; + /// let mut sv = SliceVec::from_slice_len(&mut arr, 1); + /// sv.resize(3, "world"); + /// assert_eq!(&sv[..], ["hello", "world", "world"]); + /// + /// // smaller + /// let mut arr = ['a', 'b', 'c', 'd']; + /// let mut sv = SliceVec::from(&mut arr); + /// sv.resize(2, 'z'); + /// assert_eq!(&sv[..], ['a', 'b']); + /// ``` + #[inline] + pub fn resize(&mut self, new_len: usize, new_val: T) + where + T: Clone, + { + self.resize_with(new_len, || new_val.clone()) + } + + /// Resize the vec to the new length. + /// + /// * If it needs to be longer, it's filled with repeated calls to the + /// provided function. + /// * If it needs to be shorter, it's truncated. + /// * If the type needs to drop the truncated slots are filled with calls to + /// the provided function. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [1, 2, 3, 7, 7, 7, 7]; + /// let mut sv = SliceVec::from_slice_len(&mut arr, 3); + /// sv.resize_with(5, Default::default); + /// assert_eq!(&sv[..], [1, 2, 3, 0, 0]); + /// + /// let mut arr = [0, 0, 0, 0]; + /// let mut sv = SliceVec::from_slice_len(&mut arr, 0); + /// let mut p = 1; + /// sv.resize_with(4, || { + /// p *= 2; + /// p + /// }); + /// assert_eq!(&sv[..], [2, 4, 8, 16]); + /// ``` + #[inline] + pub fn resize_with T>(&mut self, new_len: usize, mut f: F) { + match new_len.checked_sub(self.len) { + None => { + if needs_drop::() { + while self.len() > new_len { + self.len -= 1; + self.data[self.len] = f(); + } + } else { + self.len = new_len; + } + } + Some(new_elements) => { + for _ in 0..new_elements { + self.push(f()); + } + } + } + } + + /// Walk the vec and keep only the elements that pass the predicate given. + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// + /// let mut arr = [1, 1, 2, 3, 3, 4]; + /// let mut sv = SliceVec::from(&mut arr); + /// sv.retain(|&x| x % 2 == 0); + /// assert_eq!(&sv[..], [2, 4]); + /// ``` + #[inline] + pub fn retain bool>(&mut self, mut acceptable: F) + where + T: Default, + { + // Drop guard to contain exactly the remaining elements when the test + // panics. + struct JoinOnDrop<'vec, Item> { + items: &'vec mut [Item], + done_end: usize, + // Start of tail relative to `done_end`. + tail_start: usize, + } + + impl Drop for JoinOnDrop<'_, Item> { + fn drop(&mut self) { + self.items[self.done_end..].rotate_left(self.tail_start); + } + } + + let mut rest = JoinOnDrop { items: self.data, done_end: 0, tail_start: 0 }; + + for idx in 0..self.len { + // Loop start invariant: idx = rest.done_end + rest.tail_start + if !acceptable(&rest.items[idx]) { + let _ = take(&mut rest.items[idx]); + self.len -= 1; + rest.tail_start += 1; + } else { + rest.items.swap(rest.done_end, idx); + rest.done_end += 1; + } + } + } + + /// Forces the length of the vector to `new_len`. + /// + /// ## Panics + /// * If `new_len` is greater than the vec's capacity. + /// + /// ## Safety + /// * This is a fully safe operation! The inactive memory already counts as + /// "initialized" by Rust's rules. + /// * Other than "the memory is initialized" there are no other guarantees + /// regarding what you find in the inactive portion of the vec. + #[inline(always)] + pub fn set_len(&mut self, new_len: usize) { + if new_len > self.capacity() { + // Note(Lokathor): Technically we don't have to panic here, and we could + // just let some other call later on trigger a panic on accident when the + // length is wrong. However, it's a lot easier to catch bugs when things + // are more "fail-fast". + panic!( + "SliceVec::set_len> new length {} exceeds capacity {}", + new_len, + self.capacity() + ) + } else { + self.len = new_len; + } + } + + /// Splits the collection at the point given. + /// + /// * `[0, at)` stays in this vec (and this vec is now full). + /// * `[at, len)` ends up in the new vec (with any spare capacity). + /// + /// ## Panics + /// * if `at` > `self.len()` + /// + /// ## Example + /// + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [1, 2, 3]; + /// let mut sv = SliceVec::from(&mut arr); + /// let sv2 = sv.split_off(1); + /// assert_eq!(&sv[..], [1]); + /// assert_eq!(&sv2[..], [2, 3]); + /// ``` + #[inline] + pub fn split_off<'a>(&'a mut self, at: usize) -> SliceVec<'s, T> { + let mut new = Self::default(); + let backing: &'s mut [T] = replace(&mut self.data, &mut []); + let (me, other) = backing.split_at_mut(at); + new.len = self.len - at; + new.data = other; + self.len = me.len(); + self.data = me; + new + } + + /// Remove an element, swapping the end of the vec into its place. + /// + /// ## Panics + /// * If the index is out of bounds. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut arr = ["foo", "bar", "quack", "zap"]; + /// let mut sv = SliceVec::from(&mut arr); + /// + /// assert_eq!(sv.swap_remove(1), "bar"); + /// assert_eq!(&sv[..], ["foo", "zap", "quack"]); + /// + /// assert_eq!(sv.swap_remove(0), "foo"); + /// assert_eq!(&sv[..], ["quack", "zap"]); + /// ``` + #[inline] + pub fn swap_remove(&mut self, index: usize) -> T + where + T: Default, + { + assert!( + index < self.len, + "SliceVec::swap_remove> index {} is out of bounds {}", + index, + self.len + ); + if index == self.len - 1 { + self.pop().unwrap() + } else { + let i = self.pop().unwrap(); + replace(&mut self[index], i) + } + } + + /// Reduces the vec's length to the given value. + /// + /// If the vec is already shorter than the input, nothing happens. + #[inline] + pub fn truncate(&mut self, new_len: usize) + where + T: Default, + { + if needs_drop::() { + while self.len > new_len { + self.pop(); + } + } else { + self.len = self.len.min(new_len); + } + } + + /// Wraps a slice, using the given length as the starting length. + /// + /// If you want to use the whole length of the slice, you can just use the + /// `From` impl. + /// + /// ## Failure + /// + /// If the given length is greater than the length of the slice you get + /// `None`. + #[inline] + pub fn try_from_slice_len(data: &'s mut [T], len: usize) -> Option { + if len <= data.len() { + Some(Self { data, len }) + } else { + None + } + } +} + +#[cfg(feature = "grab_spare_slice")] +impl<'s, T> SliceVec<'s, T> { + /// Obtain the shared slice of the array _after_ the active memory. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [0; 4]; + /// let mut sv = SliceVec::from_slice_len(&mut arr, 0); + /// assert_eq!(sv.grab_spare_slice().len(), 4); + /// sv.push(10); + /// sv.push(11); + /// sv.push(12); + /// sv.push(13); + /// assert_eq!(sv.grab_spare_slice().len(), 0); + /// ``` + #[inline(always)] + pub fn grab_spare_slice(&self) -> &[T] { + &self.data[self.len..] + } + + /// Obtain the mutable slice of the array _after_ the active memory. + /// + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [0; 4]; + /// let mut sv = SliceVec::from_slice_len(&mut arr, 0); + /// assert_eq!(sv.grab_spare_slice_mut().len(), 4); + /// sv.push(10); + /// sv.push(11); + /// assert_eq!(sv.grab_spare_slice_mut().len(), 2); + /// ``` + #[inline(always)] + pub fn grab_spare_slice_mut(&mut self) -> &mut [T] { + &mut self.data[self.len..] + } +} + +impl<'s, T> From<&'s mut [T]> for SliceVec<'s, T> { + /// Uses the full slice as the initial length. + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [0_i32; 2]; + /// let mut sv = SliceVec::from(&mut arr[..]); + /// ``` + fn from(data: &'s mut [T]) -> Self { + let len = data.len(); + Self { data, len } + } +} + +impl<'s, T, A> From<&'s mut A> for SliceVec<'s, T> +where + A: AsMut<[T]>, +{ + /// Calls `AsRef::as_mut` then uses the full slice as the initial length. + /// ## Example + /// ```rust + /// # use tinyvec::*; + /// let mut arr = [0, 0]; + /// let mut sv = SliceVec::from(&mut arr); + /// ``` + fn from(a: &'s mut A) -> Self { + let data = a.as_mut(); + let len = data.len(); + Self { data, len } + } +} + +/// Draining iterator for [`SliceVec`] +/// +/// See [`SliceVec::drain`](SliceVec::drain) +pub struct SliceVecDrain<'p, 's, T: Default> { + parent: &'p mut SliceVec<'s, T>, + target_start: usize, + target_index: usize, + target_end: usize, +} +impl<'p, 's, T: Default> Iterator for SliceVecDrain<'p, 's, T> { + type Item = T; + #[inline] + fn next(&mut self) -> Option { + if self.target_index != self.target_end { + let out = take(&mut self.parent[self.target_index]); + self.target_index += 1; + Some(out) + } else { + None + } + } +} +impl<'p, 's, T: Default> FusedIterator for SliceVecDrain<'p, 's, T> {} +impl<'p, 's, T: Default> Drop for SliceVecDrain<'p, 's, T> { + #[inline] + fn drop(&mut self) { + // Changed because it was moving `self`, it's also more clear and the std + // does the same + self.for_each(drop); + // Implementation very similar to [`SliceVec::remove`](SliceVec::remove) + let count = self.target_end - self.target_start; + let targets: &mut [T] = &mut self.parent.deref_mut()[self.target_start..]; + targets.rotate_left(count); + self.parent.len -= count; + } +} + +impl<'s, T> AsMut<[T]> for SliceVec<'s, T> { + #[inline(always)] + #[must_use] + fn as_mut(&mut self) -> &mut [T] { + &mut *self + } +} + +impl<'s, T> AsRef<[T]> for SliceVec<'s, T> { + #[inline(always)] + #[must_use] + fn as_ref(&self) -> &[T] { + &*self + } +} + +impl<'s, T> Borrow<[T]> for SliceVec<'s, T> { + #[inline(always)] + #[must_use] + fn borrow(&self) -> &[T] { + &*self + } +} + +impl<'s, T> BorrowMut<[T]> for SliceVec<'s, T> { + #[inline(always)] + #[must_use] + fn borrow_mut(&mut self) -> &mut [T] { + &mut *self + } +} + +impl<'s, T> Extend for SliceVec<'s, T> { + #[inline] + fn extend>(&mut self, iter: I) { + for t in iter { + self.push(t) + } + } +} + +impl<'s, T> IntoIterator for SliceVec<'s, T> { + type Item = &'s mut T; + type IntoIter = core::slice::IterMut<'s, T>; + #[inline(always)] + #[must_use] + fn into_iter(self) -> Self::IntoIter { + self.data.iter_mut() + } +} + +impl<'s, T> PartialEq for SliceVec<'s, T> +where + T: PartialEq, +{ + #[inline] + #[must_use] + fn eq(&self, other: &Self) -> bool { + self.as_slice().eq(other.as_slice()) + } +} +impl<'s, T> Eq for SliceVec<'s, T> where T: Eq {} + +impl<'s, T> PartialOrd for SliceVec<'s, T> +where + T: PartialOrd, +{ + #[inline] + #[must_use] + fn partial_cmp(&self, other: &Self) -> Option { + self.as_slice().partial_cmp(other.as_slice()) + } +} +impl<'s, T> Ord for SliceVec<'s, T> +where + T: Ord, +{ + #[inline] + #[must_use] + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.as_slice().cmp(other.as_slice()) + } +} + +impl<'s, T> PartialEq<&[T]> for SliceVec<'s, T> +where + T: PartialEq, +{ + #[inline] + #[must_use] + fn eq(&self, other: &&[T]) -> bool { + self.as_slice().eq(*other) + } +} + +impl<'s, T> Hash for SliceVec<'s, T> +where + T: Hash, +{ + #[inline] + fn hash(&self, state: &mut H) { + self.as_slice().hash(state) + } +} + +#[cfg(feature = "experimental_write_impl")] +impl<'s> core::fmt::Write for SliceVec<'s, u8> { + fn write_str(&mut self, s: &str) -> core::fmt::Result { + let my_len = self.len(); + let str_len = s.as_bytes().len(); + if my_len + str_len <= self.capacity() { + let remainder = &mut self.data[my_len..]; + let target = &mut remainder[..str_len]; + target.copy_from_slice(s.as_bytes()); + Ok(()) + } else { + Err(core::fmt::Error) + } + } +} + +// // // // // // // // +// Formatting impls +// // // // // // // // + +impl<'s, T> Binary for SliceVec<'s, T> +where + T: Binary, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Binary::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl<'s, T> Debug for SliceVec<'s, T> +where + T: Debug, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Debug::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl<'s, T> Display for SliceVec<'s, T> +where + T: Display, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Display::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl<'s, T> LowerExp for SliceVec<'s, T> +where + T: LowerExp, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + LowerExp::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl<'s, T> LowerHex for SliceVec<'s, T> +where + T: LowerHex, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + LowerHex::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl<'s, T> Octal for SliceVec<'s, T> +where + T: Octal, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Octal::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl<'s, T> Pointer for SliceVec<'s, T> +where + T: Pointer, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Pointer::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl<'s, T> UpperExp for SliceVec<'s, T> +where + T: UpperExp, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + UpperExp::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl<'s, T> UpperHex for SliceVec<'s, T> +where + T: UpperHex, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + UpperHex::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} diff --git a/vendor/tinyvec/src/tinyvec.rs b/vendor/tinyvec/src/tinyvec.rs new file mode 100644 index 000000000..a5e1c1551 --- /dev/null +++ b/vendor/tinyvec/src/tinyvec.rs @@ -0,0 +1,1740 @@ +#![cfg(feature = "alloc")] + +use super::*; + +use alloc::vec::{self, Vec}; +use core::convert::TryFrom; +use tinyvec_macros::impl_mirrored; + +#[cfg(feature = "rustc_1_57")] +use alloc::collections::TryReserveError; + +#[cfg(feature = "serde")] +use core::marker::PhantomData; +#[cfg(feature = "serde")] +use serde::de::{Deserialize, Deserializer, SeqAccess, Visitor}; +#[cfg(feature = "serde")] +use serde::ser::{Serialize, SerializeSeq, Serializer}; + +/// Helper to make a `TinyVec`. +/// +/// You specify the backing array type, and optionally give all the elements you +/// want to initially place into the array. +/// +/// ```rust +/// use tinyvec::*; +/// +/// // The backing array type can be specified in the macro call +/// let empty_tv = tiny_vec!([u8; 16]); +/// let some_ints = tiny_vec!([i32; 4] => 1, 2, 3); +/// let many_ints = tiny_vec!([i32; 4] => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); +/// +/// // Or left to inference +/// let empty_tv: TinyVec<[u8; 16]> = tiny_vec!(); +/// let some_ints: TinyVec<[i32; 4]> = tiny_vec!(1, 2, 3); +/// 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")))] +macro_rules! tiny_vec { + ($array_type:ty => $($elem:expr),* $(,)?) => { + { + // https://github.com/rust-lang/lang-team/issues/28 + const INVOKED_ELEM_COUNT: usize = 0 $( + { let _ = stringify!($elem); 1 })*; + // If we have more `$elem` than the `CAPACITY` we will simply go directly + // to constructing on the heap. + match $crate::TinyVec::constructor_for_capacity(INVOKED_ELEM_COUNT) { + $crate::TinyVecConstructor::Inline(f) => { + f($crate::array_vec!($array_type => $($elem),*)) + } + $crate::TinyVecConstructor::Heap(f) => { + f(vec!($($elem),*)) + } + } + } + }; + ($array_type:ty) => { + $crate::TinyVec::<$array_type>::default() + }; + ($($elem:expr),*) => { + $crate::tiny_vec!(_ => $($elem),*) + }; + ($elem:expr; $n:expr) => { + $crate::TinyVec::from([$elem; $n]) + }; + () => { + $crate::tiny_vec!(_) + }; +} + +#[doc(hidden)] // Internal implementation details of `tiny_vec!` +pub enum TinyVecConstructor { + Inline(fn(ArrayVec) -> TinyVec), + Heap(fn(Vec) -> TinyVec), +} + +/// A vector that starts inline, but can automatically move to the heap. +/// +/// * Requires the `alloc` feature +/// +/// A `TinyVec` is either an Inline([`ArrayVec`](crate::ArrayVec::)) or +/// Heap([`Vec`](https://doc.rust-lang.org/alloc/vec/struct.Vec.html)). The +/// interface for the type as a whole is a bunch of methods that just match on +/// the enum variant and then call the same method on the inner vec. +/// +/// ## Construction +/// +/// Because it's an enum, you can construct a `TinyVec` simply by making an +/// `ArrayVec` or `Vec` and then putting it into the enum. +/// +/// There is also a macro +/// +/// ```rust +/// # use tinyvec::*; +/// 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")))] +pub enum TinyVec { + #[allow(missing_docs)] + Inline(ArrayVec), + #[allow(missing_docs)] + Heap(Vec), +} + +impl Clone for TinyVec +where + A: Array + Clone, + A::Item: Clone, +{ + #[inline] + fn clone(&self) -> Self { + match self { + TinyVec::Heap(v) => TinyVec::Heap(v.clone()), + TinyVec::Inline(v) => TinyVec::Inline(v.clone()), + } + } + + #[inline] + fn clone_from(&mut self, o: &Self) { + if o.len() > self.len() { + self.reserve(o.len() - self.len()); + } else { + self.truncate(o.len()); + } + let (start, end) = o.split_at(self.len()); + for (dst, src) in self.iter_mut().zip(start) { + dst.clone_from(src); + } + self.extend_from_slice(end); + } +} + +impl Default for TinyVec { + #[inline] + #[must_use] + fn default() -> Self { + TinyVec::Inline(ArrayVec::default()) + } +} + +impl Deref for TinyVec { + type Target = [A::Item]; + + impl_mirrored! { + type Mirror = TinyVec; + #[inline(always)] + #[must_use] + fn deref(self: &Self) -> &Self::Target; + } +} + +impl DerefMut for TinyVec { + impl_mirrored! { + type Mirror = TinyVec; + #[inline(always)] + #[must_use] + fn deref_mut(self: &mut Self) -> &mut Self::Target; + } +} + +impl> Index for TinyVec { + type Output = >::Output; + #[inline(always)] + #[must_use] + fn index(&self, index: I) -> &Self::Output { + &self.deref()[index] + } +} + +impl> IndexMut for TinyVec { + #[inline(always)] + #[must_use] + fn index_mut(&mut self, index: I) -> &mut Self::Output { + &mut self.deref_mut()[index] + } +} + +#[cfg(feature = "std")] +#[cfg_attr(docs_rs, doc(cfg(feature = "std")))] +impl> std::io::Write for TinyVec { + #[inline(always)] + fn write(&mut self, buf: &[u8]) -> std::io::Result { + self.extend_from_slice(buf); + Ok(buf.len()) + } + + #[inline(always)] + fn flush(&mut self) -> std::io::Result<()> { + Ok(()) + } +} + +#[cfg(feature = "serde")] +#[cfg_attr(docs_rs, doc(cfg(feature = "serde")))] +impl Serialize for TinyVec +where + A::Item: Serialize, +{ + #[must_use] + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut seq = serializer.serialize_seq(Some(self.len()))?; + for element in self.iter() { + seq.serialize_element(element)?; + } + seq.end() + } +} + +#[cfg(feature = "serde")] +#[cfg_attr(docs_rs, doc(cfg(feature = "serde")))] +impl<'de, A: Array> Deserialize<'de> for TinyVec +where + A::Item: Deserialize<'de>, +{ + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + deserializer.deserialize_seq(TinyVecVisitor(PhantomData)) + } +} + +#[cfg(feature = "arbitrary")] +#[cfg_attr(docs_rs, doc(cfg(feature = "arbitrary")))] +impl<'a, A> arbitrary::Arbitrary<'a> for TinyVec +where + A: Array, + A::Item: arbitrary::Arbitrary<'a>, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + let v = Vec::arbitrary(u)?; + let mut tv = TinyVec::Heap(v); + tv.shrink_to_fit(); + Ok(tv) + } +} + +impl TinyVec { + /// Returns whether elements are on heap + #[inline(always)] + #[must_use] + pub fn is_heap(&self) -> bool { + match self { + TinyVec::Heap(_) => true, + TinyVec::Inline(_) => false, + } + } + /// Returns whether elements are on stack + #[inline(always)] + #[must_use] + pub fn is_inline(&self) -> bool { + !self.is_heap() + } + + /// Shrinks the capacity of the vector as much as possible.\ + /// It is inlined if length is less than `A::CAPACITY`. + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 2] => 1, 2, 3); + /// assert!(tv.is_heap()); + /// let _ = tv.pop(); + /// assert!(tv.is_heap()); + /// tv.shrink_to_fit(); + /// assert!(tv.is_inline()); + /// ``` + pub fn shrink_to_fit(&mut self) { + let vec = match self { + TinyVec::Inline(_) => return, + TinyVec::Heap(h) => h, + }; + + if vec.len() > A::CAPACITY { + return vec.shrink_to_fit(); + } + + let moved_vec = core::mem::replace(vec, Vec::new()); + + let mut av = ArrayVec::default(); + let mut rest = av.fill(moved_vec); + debug_assert!(rest.next().is_none()); + *self = TinyVec::Inline(av); + } + + /// Moves the content of the TinyVec to the heap, if it's inline. + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3); + /// assert!(tv.is_inline()); + /// tv.move_to_the_heap(); + /// assert!(tv.is_heap()); + /// ``` + #[allow(clippy::missing_inline_in_public_items)] + pub fn move_to_the_heap(&mut self) { + let arr = match self { + TinyVec::Heap(_) => return, + TinyVec::Inline(a) => a, + }; + + let v = arr.drain_to_vec(); + *self = TinyVec::Heap(v); + } + + /// Tries to move the content of the TinyVec to the heap, if it's inline. + /// + /// # Errors + /// + /// If the allocator reports a failure, then an error is returned and the + /// content is kept on the stack. + /// + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3); + /// assert!(tv.is_inline()); + /// assert_eq!(Ok(()), tv.try_move_to_the_heap()); + /// assert!(tv.is_heap()); + /// ``` + #[cfg(feature = "rustc_1_57")] + pub fn try_move_to_the_heap(&mut self) -> Result<(), TryReserveError> { + let arr = match self { + TinyVec::Heap(_) => return Ok(()), + TinyVec::Inline(a) => a, + }; + + let v = arr.try_drain_to_vec()?; + *self = TinyVec::Heap(v); + return Ok(()); + } + + /// If TinyVec is inline, moves the content of it to the heap. + /// Also reserves additional space. + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3); + /// assert!(tv.is_inline()); + /// tv.move_to_the_heap_and_reserve(32); + /// assert!(tv.is_heap()); + /// assert!(tv.capacity() >= 35); + /// ``` + pub fn move_to_the_heap_and_reserve(&mut self, n: usize) { + let arr = match self { + TinyVec::Heap(h) => return h.reserve(n), + TinyVec::Inline(a) => a, + }; + + let v = arr.drain_to_vec_and_reserve(n); + *self = TinyVec::Heap(v); + } + + /// If TinyVec is inline, try to move the content of it to the heap. + /// Also reserves additional space. + /// + /// # Errors + /// + /// If the allocator reports a failure, then an error is returned. + /// + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3); + /// assert!(tv.is_inline()); + /// assert_eq!(Ok(()), tv.try_move_to_the_heap_and_reserve(32)); + /// assert!(tv.is_heap()); + /// assert!(tv.capacity() >= 35); + /// ``` + #[cfg(feature = "rustc_1_57")] + pub fn try_move_to_the_heap_and_reserve( + &mut self, n: usize, + ) -> Result<(), TryReserveError> { + let arr = match self { + TinyVec::Heap(h) => return h.try_reserve(n), + TinyVec::Inline(a) => a, + }; + + let v = arr.try_drain_to_vec_and_reserve(n)?; + *self = TinyVec::Heap(v); + return Ok(()); + } + + /// Reserves additional space. + /// Moves to the heap if array can't hold `n` more items + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3, 4); + /// assert!(tv.is_inline()); + /// tv.reserve(1); + /// assert!(tv.is_heap()); + /// assert!(tv.capacity() >= 5); + /// ``` + pub fn reserve(&mut self, n: usize) { + let arr = match self { + TinyVec::Heap(h) => return h.reserve(n), + TinyVec::Inline(a) => a, + }; + + if n > arr.capacity() - arr.len() { + let v = arr.drain_to_vec_and_reserve(n); + *self = TinyVec::Heap(v); + } + + /* In this place array has enough place, so no work is needed more */ + return; + } + + /// Tries to reserve additional space. + /// Moves to the heap if array can't hold `n` more items. + /// + /// # Errors + /// + /// If the allocator reports a failure, then an error is returned. + /// + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3, 4); + /// assert!(tv.is_inline()); + /// assert_eq!(Ok(()), tv.try_reserve(1)); + /// assert!(tv.is_heap()); + /// assert!(tv.capacity() >= 5); + /// ``` + #[cfg(feature = "rustc_1_57")] + pub fn try_reserve(&mut self, n: usize) -> Result<(), TryReserveError> { + let arr = match self { + TinyVec::Heap(h) => return h.try_reserve(n), + TinyVec::Inline(a) => a, + }; + + if n > arr.capacity() - arr.len() { + let v = arr.try_drain_to_vec_and_reserve(n)?; + *self = TinyVec::Heap(v); + } + + /* In this place array has enough place, so no work is needed more */ + return Ok(()); + } + + /// Reserves additional space. + /// Moves to the heap if array can't hold `n` more items + /// + /// From [Vec::reserve_exact](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.reserve_exact) + /// ```text + /// Note that the allocator may give the collection more space than it requests. + /// Therefore, capacity can not be relied upon to be precisely minimal. + /// Prefer `reserve` if future insertions are expected. + /// ``` + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3, 4); + /// assert!(tv.is_inline()); + /// tv.reserve_exact(1); + /// assert!(tv.is_heap()); + /// assert!(tv.capacity() >= 5); + /// ``` + pub fn reserve_exact(&mut self, n: usize) { + let arr = match self { + TinyVec::Heap(h) => return h.reserve_exact(n), + TinyVec::Inline(a) => a, + }; + + if n > arr.capacity() - arr.len() { + let v = arr.drain_to_vec_and_reserve(n); + *self = TinyVec::Heap(v); + } + + /* In this place array has enough place, so no work is needed more */ + return; + } + + /// Tries to reserve additional space. + /// Moves to the heap if array can't hold `n` more items + /// + /// # Errors + /// + /// If the allocator reports a failure, then an error is returned. + /// + /// From [Vec::try_reserve_exact](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.try_reserve_exact) + /// ```text + /// Note that the allocator may give the collection more space than it requests. + /// Therefore, capacity can not be relied upon to be precisely minimal. + /// Prefer `reserve` if future insertions are expected. + /// ``` + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3, 4); + /// assert!(tv.is_inline()); + /// assert_eq!(Ok(()), tv.try_reserve_exact(1)); + /// assert!(tv.is_heap()); + /// assert!(tv.capacity() >= 5); + /// ``` + #[cfg(feature = "rustc_1_57")] + pub fn try_reserve_exact(&mut self, n: usize) -> Result<(), TryReserveError> { + let arr = match self { + TinyVec::Heap(h) => return h.try_reserve_exact(n), + TinyVec::Inline(a) => a, + }; + + if n > arr.capacity() - arr.len() { + let v = arr.try_drain_to_vec_and_reserve(n)?; + *self = TinyVec::Heap(v); + } + + /* In this place array has enough place, so no work is needed more */ + return Ok(()); + } + + /// Makes a new TinyVec with _at least_ the given capacity. + /// + /// If the requested capacity is less than or equal to the array capacity you + /// get an inline vec. If it's greater than you get a heap vec. + /// ``` + /// # use tinyvec::*; + /// let t = TinyVec::<[u8; 10]>::with_capacity(5); + /// assert!(t.is_inline()); + /// assert!(t.capacity() >= 5); + /// + /// let t = TinyVec::<[u8; 10]>::with_capacity(20); + /// assert!(t.is_heap()); + /// assert!(t.capacity() >= 20); + /// ``` + #[inline] + #[must_use] + pub fn with_capacity(cap: usize) -> Self { + if cap <= A::CAPACITY { + TinyVec::Inline(ArrayVec::default()) + } else { + TinyVec::Heap(Vec::with_capacity(cap)) + } + } +} + +impl TinyVec { + /// Move all values from `other` into this vec. + #[cfg(feature = "rustc_1_40")] + #[inline] + pub fn append(&mut self, other: &mut Self) { + self.reserve(other.len()); + + /* Doing append should be faster, because it is effectively a memcpy */ + match (self, other) { + (TinyVec::Heap(sh), TinyVec::Heap(oh)) => sh.append(oh), + (TinyVec::Inline(a), TinyVec::Heap(h)) => a.extend(h.drain(..)), + (ref mut this, TinyVec::Inline(arr)) => this.extend(arr.drain(..)), + } + } + + /// Move all values from `other` into this vec. + #[cfg(not(feature = "rustc_1_40"))] + #[inline] + pub fn append(&mut self, other: &mut Self) { + match other { + TinyVec::Inline(a) => self.extend(a.drain(..)), + TinyVec::Heap(h) => self.extend(h.drain(..)), + } + } + + impl_mirrored! { + type Mirror = TinyVec; + + /// Remove an element, swapping the end of the vec into its place. + /// + /// ## Panics + /// * If the index is out of bounds. + /// + /// ## Example + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([&str; 4] => "foo", "bar", "quack", "zap"); + /// + /// assert_eq!(tv.swap_remove(1), "bar"); + /// assert_eq!(tv.as_slice(), &["foo", "zap", "quack"][..]); + /// + /// assert_eq!(tv.swap_remove(0), "foo"); + /// assert_eq!(tv.as_slice(), &["quack", "zap"][..]); + /// ``` + #[inline] + pub fn swap_remove(self: &mut Self, index: usize) -> A::Item; + + /// Remove and return the last element of the vec, if there is one. + /// + /// ## Failure + /// * If the vec is empty you get `None`. + #[inline] + pub fn pop(self: &mut Self) -> Option; + + /// Removes the item at `index`, shifting all others down by one index. + /// + /// Returns the removed element. + /// + /// ## Panics + /// + /// If the index is out of bounds. + /// + /// ## Example + /// + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3); + /// assert_eq!(tv.remove(1), 2); + /// assert_eq!(tv.as_slice(), &[1, 3][..]); + /// ``` + #[inline] + pub fn remove(self: &mut Self, index: usize) -> A::Item; + + /// The length of the vec (in elements). + #[inline(always)] + #[must_use] + pub fn len(self: &Self) -> usize; + + /// The capacity of the `TinyVec`. + /// + /// When not heap allocated this is fixed based on the array type. + /// Otherwise its the result of the underlying Vec::capacity. + #[inline(always)] + #[must_use] + pub fn capacity(self: &Self) -> usize; + + /// Reduces the vec's length to the given value. + /// + /// If the vec is already shorter than the input, nothing happens. + #[inline] + pub fn truncate(self: &mut Self, new_len: usize); + + /// A mutable pointer to the backing array. + /// + /// ## Safety + /// + /// This pointer has provenance over the _entire_ backing array/buffer. + #[inline(always)] + #[must_use] + pub fn as_mut_ptr(self: &mut Self) -> *mut A::Item; + + /// A const pointer to the backing array. + /// + /// ## Safety + /// + /// This pointer has provenance over the _entire_ backing array/buffer. + #[inline(always)] + #[must_use] + pub fn as_ptr(self: &Self) -> *const A::Item; + } + + /// Walk the vec and keep only the elements that pass the predicate given. + /// + /// ## Example + /// + /// ```rust + /// use tinyvec::*; + /// + /// let mut tv = tiny_vec!([i32; 10] => 1, 2, 3, 4); + /// tv.retain(|&x| x % 2 == 0); + /// assert_eq!(tv.as_slice(), &[2, 4][..]); + /// ``` + #[inline] + pub fn retain bool>(self: &mut Self, acceptable: F) { + match self { + TinyVec::Inline(i) => i.retain(acceptable), + TinyVec::Heap(h) => h.retain(acceptable), + } + } + + /// Helper for getting the mut slice. + #[inline(always)] + #[must_use] + pub fn as_mut_slice(self: &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] { + self.deref() + } + + /// Removes all elements from the vec. + #[inline(always)] + pub fn clear(&mut self) { + self.truncate(0) + } + + /// De-duplicates the vec. + #[cfg(feature = "nightly_slice_partition_dedup")] + #[inline(always)] + pub fn dedup(&mut self) + where + A::Item: PartialEq, + { + self.dedup_by(|a, b| a == b) + } + + /// De-duplicates the vec according to the predicate given. + #[cfg(feature = "nightly_slice_partition_dedup")] + #[inline(always)] + pub fn dedup_by(&mut self, same_bucket: F) + where + F: FnMut(&mut A::Item, &mut A::Item) -> bool, + { + let len = { + let (dedup, _) = self.as_mut_slice().partition_dedup_by(same_bucket); + dedup.len() + }; + self.truncate(len); + } + + /// De-duplicates the vec according to the key selector given. + #[cfg(feature = "nightly_slice_partition_dedup")] + #[inline(always)] + pub fn dedup_by_key(&mut self, mut key: F) + where + F: FnMut(&mut A::Item) -> K, + K: PartialEq, + { + self.dedup_by(|a, b| key(a) == key(b)) + } + + /// Creates a draining iterator that removes the specified range in the vector + /// and yields the removed items. + /// + /// **Note: This method has significant performance issues compared to + /// matching on the TinyVec and then calling drain on the Inline or Heap value + /// inside. The draining iterator has to branch on every single access. It is + /// provided for simplicity and compatability only.** + /// + /// ## Panics + /// * If the start is greater than the end + /// * If the end is past the edge of the vec. + /// + /// ## Example + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3); + /// let tv2: TinyVec<[i32; 4]> = tv.drain(1..).collect(); + /// assert_eq!(tv.as_slice(), &[1][..]); + /// assert_eq!(tv2.as_slice(), &[2, 3][..]); + /// + /// tv.drain(..); + /// assert_eq!(tv.as_slice(), &[]); + /// ``` + #[inline] + pub fn drain>( + &mut self, range: R, + ) -> TinyVecDrain<'_, A> { + match self { + TinyVec::Inline(i) => TinyVecDrain::Inline(i.drain(range)), + TinyVec::Heap(h) => TinyVecDrain::Heap(h.drain(range)), + } + } + + /// Clone each element of the slice into this vec. + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2); + /// tv.extend_from_slice(&[3, 4]); + /// assert_eq!(tv.as_slice(), [1, 2, 3, 4]); + /// ``` + #[inline] + pub fn extend_from_slice(&mut self, sli: &[A::Item]) + where + A::Item: Clone, + { + self.reserve(sli.len()); + match self { + TinyVec::Inline(a) => a.extend_from_slice(sli), + TinyVec::Heap(h) => h.extend_from_slice(sli), + } + } + + /// Wraps up an array and uses the given length as the initial length. + /// + /// Note that the `From` impl for arrays assumes the full length is used. + /// + /// ## Panics + /// + /// The length must be less than or equal to the capacity of the array. + #[inline] + #[must_use] + #[allow(clippy::match_wild_err_arm)] + pub fn from_array_len(data: A, len: usize) -> Self { + match Self::try_from_array_len(data, len) { + Ok(out) => out, + Err(_) => { + panic!("TinyVec: length {} exceeds capacity {}!", len, A::CAPACITY) + } + } + } + + /// This is an internal implementation detail of the `tiny_vec!` macro, and + /// using it other than from that macro is not supported by this crate's + /// SemVer guarantee. + #[inline(always)] + #[doc(hidden)] + pub fn constructor_for_capacity(cap: usize) -> TinyVecConstructor { + if cap <= A::CAPACITY { + TinyVecConstructor::Inline(TinyVec::Inline) + } else { + TinyVecConstructor::Heap(TinyVec::Heap) + } + } + + /// Inserts an item at the position given, moving all following elements +1 + /// index. + /// + /// ## Panics + /// * If `index` > `len` + /// + /// ## Example + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 10] => 1, 2, 3); + /// tv.insert(1, 4); + /// assert_eq!(tv.as_slice(), &[1, 4, 2, 3]); + /// tv.insert(4, 5); + /// assert_eq!(tv.as_slice(), &[1, 4, 2, 3, 5]); + /// ``` + #[inline] + pub fn insert(&mut self, index: usize, item: A::Item) { + assert!( + index <= self.len(), + "insertion index (is {}) should be <= len (is {})", + index, + self.len() + ); + + let arr = match self { + TinyVec::Heap(v) => return v.insert(index, item), + TinyVec::Inline(a) => 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())); + v.extend(it.by_ref().take(index)); + v.push(x); + v.extend(it); + *self = TinyVec::Heap(v); + } + } + + /// If the vec is empty. + #[inline(always)] + #[must_use] + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + + /// Makes a new, empty vec. + #[inline(always)] + #[must_use] + pub fn new() -> Self { + Self::default() + } + + /// Place an element onto the end of the vec. + /// ## Panics + /// * If the length of the vec would overflow the capacity. + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 10] => 1, 2, 3); + /// tv.push(4); + /// assert_eq!(tv.as_slice(), &[1, 2, 3, 4]); + /// ``` + #[inline] + pub fn push(&mut self, val: A::Item) { + // The code path for moving the inline contents to the heap produces a lot + // of instructions, but we have a strong guarantee that this is a cold + // path. LLVM doesn't know this, inlines it, and this tends to cause a + // cascade of other bad inlining decisions because the body of push looks + // huge even though nearly every call executes the same few instructions. + // + // Moving the logic out of line with #[cold] causes the hot code to be + // inlined together, and we take the extra cost of a function call only + // in rare cases. + #[cold] + fn drain_to_heap_and_push( + arr: &mut ArrayVec, val: A::Item, + ) -> TinyVec { + /* Make the Vec twice the size to amortize the cost of draining */ + let mut v = arr.drain_to_vec_and_reserve(arr.len()); + v.push(val); + TinyVec::Heap(v) + } + + match self { + TinyVec::Heap(v) => v.push(val), + TinyVec::Inline(arr) => { + if let Some(x) = arr.try_push(val) { + *self = drain_to_heap_and_push(arr, x); + } + } + } + } + + /// Resize the vec to the new length. + /// + /// If it needs to be longer, it's filled with clones of the provided value. + /// If it needs to be shorter, it's truncated. + /// + /// ## Example + /// + /// ```rust + /// use tinyvec::*; + /// + /// let mut tv = tiny_vec!([&str; 10] => "hello"); + /// tv.resize(3, "world"); + /// assert_eq!(tv.as_slice(), &["hello", "world", "world"][..]); + /// + /// let mut tv = tiny_vec!([i32; 10] => 1, 2, 3, 4); + /// tv.resize(2, 0); + /// assert_eq!(tv.as_slice(), &[1, 2][..]); + /// ``` + #[inline] + pub fn resize(&mut self, new_len: usize, new_val: A::Item) + where + A::Item: Clone, + { + self.resize_with(new_len, || new_val.clone()); + } + + /// Resize the vec to the new length. + /// + /// If it needs to be longer, it's filled with repeated calls to the provided + /// function. If it needs to be shorter, it's truncated. + /// + /// ## Example + /// + /// ```rust + /// use tinyvec::*; + /// + /// let mut tv = tiny_vec!([i32; 3] => 1, 2, 3); + /// tv.resize_with(5, Default::default); + /// assert_eq!(tv.as_slice(), &[1, 2, 3, 0, 0][..]); + /// + /// let mut tv = tiny_vec!([i32; 2]); + /// let mut p = 1; + /// tv.resize_with(4, || { + /// p *= 2; + /// p + /// }); + /// assert_eq!(tv.as_slice(), &[2, 4, 8, 16][..]); + /// ``` + #[inline] + pub fn resize_with A::Item>(&mut self, new_len: usize, f: F) { + match new_len.checked_sub(self.len()) { + None => return self.truncate(new_len), + Some(n) => self.reserve(n), + } + + match self { + TinyVec::Inline(a) => a.resize_with(new_len, f), + TinyVec::Heap(v) => v.resize_with(new_len, f), + } + } + + /// Splits the collection at the point given. + /// + /// * `[0, at)` stays in this vec + /// * `[at, len)` ends up in the new vec. + /// + /// ## Panics + /// * if at > len + /// + /// ## Example + /// + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3); + /// let tv2 = tv.split_off(1); + /// assert_eq!(tv.as_slice(), &[1][..]); + /// assert_eq!(tv2.as_slice(), &[2, 3][..]); + /// ``` + #[inline] + pub fn split_off(&mut self, at: usize) -> Self { + match self { + TinyVec::Inline(a) => TinyVec::Inline(a.split_off(at)), + TinyVec::Heap(v) => TinyVec::Heap(v.split_off(at)), + } + } + + /// Creates a splicing iterator that removes the specified range in the + /// vector, yields the removed items, and replaces them with elements from + /// the provided iterator. + /// + /// `splice` fuses the provided iterator, so elements after the first `None` + /// are ignored. + /// + /// ## Panics + /// * If the start is greater than the end. + /// * If the end is past the edge of the vec. + /// * If the provided iterator panics. + /// + /// ## Example + /// ```rust + /// use tinyvec::*; + /// let mut tv = tiny_vec!([i32; 4] => 1, 2, 3); + /// let tv2: TinyVec<[i32; 4]> = tv.splice(1.., 4..=6).collect(); + /// assert_eq!(tv.as_slice(), &[1, 4, 5, 6][..]); + /// assert_eq!(tv2.as_slice(), &[2, 3][..]); + /// + /// tv.splice(.., None); + /// assert_eq!(tv.as_slice(), &[]); + /// ``` + #[inline] + pub fn splice( + &mut self, range: R, replacement: I, + ) -> TinyVecSplice<'_, A, core::iter::Fuse> + where + R: RangeBounds, + I: IntoIterator, + { + use core::ops::Bound; + let start = match range.start_bound() { + Bound::Included(x) => *x, + Bound::Excluded(x) => x.saturating_add(1), + Bound::Unbounded => 0, + }; + let end = match range.end_bound() { + Bound::Included(x) => x.saturating_add(1), + Bound::Excluded(x) => *x, + Bound::Unbounded => self.len(), + }; + assert!( + start <= end, + "TinyVec::splice> Illegal range, {} to {}", + start, + end + ); + assert!( + end <= self.len(), + "TinyVec::splice> Range ends at {} but length is only {}!", + end, + self.len() + ); + + TinyVecSplice { + removal_start: start, + removal_end: end, + parent: self, + replacement: replacement.into_iter().fuse(), + } + } + + /// 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] + pub fn try_from_array_len(data: A, len: usize) -> Result { + let arr = ArrayVec::try_from_array_len(data, len)?; + Ok(TinyVec::Inline(arr)) + } +} + +/// Draining iterator for `TinyVecDrain` +/// +/// See [`TinyVecDrain::drain`](TinyVecDrain::::drain) +#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +pub enum TinyVecDrain<'p, A: Array> { + #[allow(missing_docs)] + Inline(ArrayVecDrain<'p, A::Item>), + #[allow(missing_docs)] + Heap(vec::Drain<'p, A::Item>), +} + +impl<'p, A: Array> Iterator for TinyVecDrain<'p, A> { + type Item = A::Item; + + impl_mirrored! { + type Mirror = TinyVecDrain; + + #[inline] + fn next(self: &mut Self) -> Option; + #[inline] + fn nth(self: &mut Self, n: usize) -> Option; + #[inline] + fn size_hint(self: &Self) -> (usize, Option); + #[inline] + fn last(self: Self) -> Option; + #[inline] + fn count(self: Self) -> usize; + } + + #[inline] + fn for_each(self, f: F) { + match self { + TinyVecDrain::Inline(i) => i.for_each(f), + TinyVecDrain::Heap(h) => h.for_each(f), + } + } +} + +impl<'p, A: Array> DoubleEndedIterator for TinyVecDrain<'p, A> { + impl_mirrored! { + type Mirror = TinyVecDrain; + + #[inline] + fn next_back(self: &mut Self) -> Option; + + #[cfg(feature = "rustc_1_40")] + #[inline] + fn nth_back(self: &mut Self, n: usize) -> Option; + } +} + +/// Splicing iterator for `TinyVec` +/// See [`TinyVec::splice`](TinyVec::::splice) +#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +pub struct TinyVecSplice<'p, A: Array, I: Iterator> { + parent: &'p mut TinyVec, + removal_start: usize, + removal_end: usize, + replacement: I, +} + +impl<'p, A, I> Iterator for TinyVecSplice<'p, A, I> +where + A: Array, + I: Iterator, +{ + type Item = A::Item; + + #[inline] + fn next(&mut self) -> Option { + if self.removal_start < self.removal_end { + match self.replacement.next() { + Some(replacement) => { + let removed = core::mem::replace( + &mut self.parent[self.removal_start], + replacement, + ); + self.removal_start += 1; + Some(removed) + } + None => { + let removed = self.parent.remove(self.removal_start); + self.removal_end -= 1; + Some(removed) + } + } + } else { + None + } + } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + let len = self.len(); + (len, Some(len)) + } +} + +impl<'p, A, I> ExactSizeIterator for TinyVecSplice<'p, A, I> +where + A: Array, + I: Iterator, +{ + #[inline] + fn len(&self) -> usize { + self.removal_end - self.removal_start + } +} + +impl<'p, A, I> FusedIterator for TinyVecSplice<'p, A, I> +where + A: Array, + I: Iterator, +{ +} + +impl<'p, A, I> DoubleEndedIterator for TinyVecSplice<'p, A, I> +where + A: Array, + I: Iterator + DoubleEndedIterator, +{ + #[inline] + fn next_back(&mut self) -> Option { + if self.removal_start < self.removal_end { + match self.replacement.next_back() { + Some(replacement) => { + let removed = core::mem::replace( + &mut self.parent[self.removal_end - 1], + replacement, + ); + self.removal_end -= 1; + Some(removed) + } + None => { + let removed = self.parent.remove(self.removal_end - 1); + self.removal_end -= 1; + Some(removed) + } + } + } else { + None + } + } +} + +impl<'p, A: Array, I: Iterator> Drop + for TinyVecSplice<'p, A, I> +{ + fn drop(&mut self) { + for _ in self.by_ref() {} + + let (lower_bound, _) = self.replacement.size_hint(); + self.parent.reserve(lower_bound); + + for replacement in self.replacement.by_ref() { + self.parent.insert(self.removal_end, replacement); + self.removal_end += 1; + } + } +} + +impl AsMut<[A::Item]> for TinyVec { + #[inline(always)] + #[must_use] + fn as_mut(&mut self) -> &mut [A::Item] { + &mut *self + } +} + +impl AsRef<[A::Item]> for TinyVec { + #[inline(always)] + #[must_use] + fn as_ref(&self) -> &[A::Item] { + &*self + } +} + +impl Borrow<[A::Item]> for TinyVec { + #[inline(always)] + #[must_use] + fn borrow(&self) -> &[A::Item] { + &*self + } +} + +impl BorrowMut<[A::Item]> for TinyVec { + #[inline(always)] + #[must_use] + fn borrow_mut(&mut self) -> &mut [A::Item] { + &mut *self + } +} + +impl Extend for TinyVec { + #[inline] + fn extend>(&mut self, iter: T) { + let iter = iter.into_iter(); + let (lower_bound, _) = iter.size_hint(); + self.reserve(lower_bound); + + let a = match self { + TinyVec::Heap(h) => return h.extend(iter), + TinyVec::Inline(a) => a, + }; + + let mut iter = a.fill(iter); + let maybe = iter.next(); + + let surely = match maybe { + Some(x) => x, + None => return, + }; + + let mut v = a.drain_to_vec_and_reserve(a.len()); + v.push(surely); + v.extend(iter); + *self = TinyVec::Heap(v); + } +} + +impl From> for TinyVec { + #[inline(always)] + #[must_use] + fn from(arr: ArrayVec) -> Self { + TinyVec::Inline(arr) + } +} + +impl From for TinyVec { + fn from(array: A) -> Self { + TinyVec::Inline(ArrayVec::from(array)) + } +} + +impl From<&'_ [T]> for TinyVec +where + T: Clone + Default, + A: Array, +{ + #[inline] + #[must_use] + fn from(slice: &[T]) -> Self { + if let Ok(arr) = ArrayVec::try_from(slice) { + TinyVec::Inline(arr) + } else { + TinyVec::Heap(slice.into()) + } + } +} + +impl From<&'_ mut [T]> for TinyVec +where + T: Clone + Default, + A: Array, +{ + #[inline] + #[must_use] + fn from(slice: &mut [T]) -> Self { + Self::from(&*slice) + } +} + +impl FromIterator for TinyVec { + #[inline] + #[must_use] + fn from_iter>(iter: T) -> Self { + let mut av = Self::default(); + av.extend(iter); + av + } +} + +/// Iterator for consuming an `TinyVec` and returning owned elements. +#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +pub enum TinyVecIterator { + #[allow(missing_docs)] + Inline(ArrayVecIterator), + #[allow(missing_docs)] + Heap(alloc::vec::IntoIter), +} + +impl TinyVecIterator { + impl_mirrored! { + type Mirror = TinyVecIterator; + /// Returns the remaining items of this iterator as a slice. + #[inline] + #[must_use] + pub fn as_slice(self: &Self) -> &[A::Item]; + } +} + +impl FusedIterator for TinyVecIterator {} + +impl Iterator for TinyVecIterator { + type Item = A::Item; + + impl_mirrored! { + type Mirror = TinyVecIterator; + + #[inline] + fn next(self: &mut Self) -> Option; + + #[inline(always)] + #[must_use] + fn size_hint(self: &Self) -> (usize, Option); + + #[inline(always)] + fn count(self: Self) -> usize; + + #[inline] + fn last(self: Self) -> Option; + + #[inline] + fn nth(self: &mut Self, n: usize) -> Option; + } +} + +impl DoubleEndedIterator for TinyVecIterator { + impl_mirrored! { + type Mirror = TinyVecIterator; + + #[inline] + fn next_back(self: &mut Self) -> Option; + + #[cfg(feature = "rustc_1_40")] + #[inline] + fn nth_back(self: &mut Self, n: usize) -> Option; + } +} + +impl Debug for TinyVecIterator +where + A::Item: Debug, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { + f.debug_tuple("TinyVecIterator").field(&self.as_slice()).finish() + } +} + +impl IntoIterator for TinyVec { + type Item = A::Item; + type IntoIter = TinyVecIterator; + #[inline(always)] + #[must_use] + fn into_iter(self) -> Self::IntoIter { + match self { + TinyVec::Inline(a) => TinyVecIterator::Inline(a.into_iter()), + TinyVec::Heap(v) => TinyVecIterator::Heap(v.into_iter()), + } + } +} + +impl<'a, A: Array> IntoIterator for &'a mut TinyVec { + type Item = &'a mut A::Item; + type IntoIter = core::slice::IterMut<'a, A::Item>; + #[inline(always)] + #[must_use] + fn into_iter(self) -> Self::IntoIter { + self.iter_mut() + } +} + +impl<'a, A: Array> IntoIterator for &'a TinyVec { + type Item = &'a A::Item; + type IntoIter = core::slice::Iter<'a, A::Item>; + #[inline(always)] + #[must_use] + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +impl PartialEq for TinyVec +where + A::Item: PartialEq, +{ + #[inline] + #[must_use] + fn eq(&self, other: &Self) -> bool { + self.as_slice().eq(other.as_slice()) + } +} +impl Eq for TinyVec where A::Item: Eq {} + +impl PartialOrd for TinyVec +where + A::Item: PartialOrd, +{ + #[inline] + #[must_use] + fn partial_cmp(&self, other: &Self) -> Option { + self.as_slice().partial_cmp(other.as_slice()) + } +} +impl Ord for TinyVec +where + A::Item: Ord, +{ + #[inline] + #[must_use] + fn cmp(&self, other: &Self) -> core::cmp::Ordering { + self.as_slice().cmp(other.as_slice()) + } +} + +impl PartialEq<&A> for TinyVec +where + A::Item: PartialEq, +{ + #[inline] + #[must_use] + fn eq(&self, other: &&A) -> bool { + self.as_slice().eq(other.as_slice()) + } +} + +impl PartialEq<&[A::Item]> for TinyVec +where + A::Item: PartialEq, +{ + #[inline] + #[must_use] + fn eq(&self, other: &&[A::Item]) -> bool { + self.as_slice().eq(*other) + } +} + +impl Hash for TinyVec +where + A::Item: Hash, +{ + #[inline] + fn hash(&self, state: &mut H) { + self.as_slice().hash(state) + } +} + +// // // // // // // // +// Formatting impls +// // // // // // // // + +impl Binary for TinyVec +where + A::Item: Binary, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Binary::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl Debug for TinyVec +where + A::Item: Debug, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Debug::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl Display for TinyVec +where + A::Item: Display, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Display::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl LowerExp for TinyVec +where + A::Item: LowerExp, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + LowerExp::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl LowerHex for TinyVec +where + A::Item: LowerHex, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + LowerHex::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl Octal for TinyVec +where + A::Item: Octal, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Octal::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl Pointer for TinyVec +where + A::Item: Pointer, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + Pointer::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl UpperExp for TinyVec +where + A::Item: UpperExp, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + UpperExp::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +impl UpperHex for TinyVec +where + A::Item: UpperHex, +{ + #[allow(clippy::missing_inline_in_public_items)] + fn fmt(&self, f: &mut Formatter) -> core::fmt::Result { + write!(f, "[")?; + if f.alternate() { + write!(f, "\n ")?; + } + for (i, elem) in self.iter().enumerate() { + if i > 0 { + write!(f, ",{}", if f.alternate() { "\n " } else { " " })?; + } + UpperHex::fmt(elem, f)?; + } + if f.alternate() { + write!(f, ",\n")?; + } + write!(f, "]") + } +} + +#[cfg(feature = "serde")] +#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +struct TinyVecVisitor(PhantomData); + +#[cfg(feature = "serde")] +impl<'de, A: Array> Visitor<'de> for TinyVecVisitor +where + A::Item: Deserialize<'de>, +{ + type Value = TinyVec; + + fn expecting( + &self, formatter: &mut core::fmt::Formatter, + ) -> core::fmt::Result { + formatter.write_str("a sequence") + } + + fn visit_seq(self, mut seq: S) -> Result + where + S: SeqAccess<'de>, + { + let mut new_tinyvec = match seq.size_hint() { + Some(expected_size) => TinyVec::with_capacity(expected_size), + None => Default::default(), + }; + + while let Some(value) = seq.next_element()? { + new_tinyvec.push(value); + } + + Ok(new_tinyvec) + } +} -- cgit v1.2.3