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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ specialization = []
may_dangle = []
serde = ["dep:serde_core"]
internals = []
default = ["allocator-api2"]

[dependencies]
allocator-api2 = { version = "0.4", optional = true, features = ["alloc"], default-features = false }
arbitrary = { version = "1.4", optional = true, default-features = false }
borsh = { version = "1.8", optional = true, features = ["derive", "unstable__schema"], default-features = false }
bytes = { version = "1.12", optional = true, default-features = false }
Expand Down
47 changes: 25 additions & 22 deletions src/comparisons.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use {
crate::SmallVec,
crate::{
Allocator,
SmallVec
},
alloc::{
borrow::Cow,
collections::VecDeque,
Expand All @@ -9,7 +12,7 @@ use {

macro_rules! __impl_slice_eq1 {
([$($vars:tt)*] $lhs:ty, $rhs:ty $(where $ty:ty: $bound:ident)?) => {
impl<T, U, $($vars)*> PartialEq<$rhs> for $lhs
impl<T, U, A: Allocator, $($vars)*> PartialEq<$rhs> for $lhs
where
T: PartialEq<U>,
$($ty: $bound)?
Expand All @@ -20,25 +23,25 @@ macro_rules! __impl_slice_eq1 {
};
}

__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec<T, M>, SmallVec<U, N> }
__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec<T, M>, [U; N] }
__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec<T, M>, &[U; N] }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N>, [U] }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N>, &[U] }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N>, &mut [U] }
__impl_slice_eq1! { [const N: usize] [T], SmallVec<U, N> }
__impl_slice_eq1! { [const N: usize] &[T], SmallVec<U, N> }
__impl_slice_eq1! { [const N: usize] &mut [T], SmallVec<U, N> }
__impl_slice_eq1! { [const N: usize] Vec<T>, SmallVec<U, N> }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N>, Vec<U> }
__impl_slice_eq1! { [const N: usize] Cow<'_, [T]>, SmallVec<U, N> where T: Clone }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N>, Cow<'_, [U]> where U: Clone }
__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec<T, M, A>, SmallVec<U, N, A> }
__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec<T, M, A>, [U; N] }
__impl_slice_eq1! { [const N: usize, const M: usize] SmallVec<T, M, A>, &[U; N] }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N, A>, [U] }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N, A>, &[U] }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N, A>, &mut [U] }
__impl_slice_eq1! { [const N: usize] [T], SmallVec<U, N, A> }
__impl_slice_eq1! { [const N: usize] &[T], SmallVec<U, N, A> }
__impl_slice_eq1! { [const N: usize] &mut [T], SmallVec<U, N, A> }
__impl_slice_eq1! { [const N: usize] Vec<T>, SmallVec<U, N, A> }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N, A>, Vec<U> }
__impl_slice_eq1! { [const N: usize] Cow<'_, [T]>, SmallVec<U, N, A> where T: Clone }
__impl_slice_eq1! { [const N: usize] SmallVec<T, N, A>, Cow<'_, [U]> where U: Clone }

impl<T, U, const N: usize> PartialEq<SmallVec<U, N>> for VecDeque<T>
impl<T, U, const N: usize, A: Allocator> PartialEq<SmallVec<U, N, A>> for VecDeque<T>
where T: PartialEq<U>
{
#[inline]
fn eq(&self, other: &SmallVec<U, N>) -> bool {
fn eq(&self, other: &SmallVec<U, N, A>) -> bool {
let other = other.as_slice();
if self.len() != other.len() {
return false;
Expand All @@ -49,22 +52,22 @@ where T: PartialEq<U>
}
}

impl<T, const N: usize> Eq for SmallVec<T, N> where T: Eq {}
impl<T, const N: usize, A: Allocator> Eq for SmallVec<T, N, A> where T: Eq {}

impl<T, const N: usize> PartialOrd for SmallVec<T, N>
impl<T, const N: usize, A: Allocator> PartialOrd for SmallVec<T, N, A>
where T: PartialOrd
{
#[inline]
fn partial_cmp(&self, other: &SmallVec<T, N>) -> Option<core::cmp::Ordering> {
fn partial_cmp(&self, other: &SmallVec<T, N, A>) -> Option<core::cmp::Ordering> {
self.as_slice().partial_cmp(other.as_slice())
}
}

impl<T, const N: usize> Ord for SmallVec<T, N>
impl<T, const N: usize, A: Allocator> Ord for SmallVec<T, N, A>
where T: Ord
{
#[inline]
fn cmp(&self, other: &SmallVec<T, N>) -> core::cmp::Ordering {
fn cmp(&self, other: &SmallVec<T, N, A>) -> core::cmp::Ordering {
self.as_slice().cmp(other.as_slice())
}
}
11 changes: 7 additions & 4 deletions src/conversions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use {
crate::SmallVec,
crate::{
Allocator,
SmallVec
},
alloc::vec::Vec,
core::{
mem::ManuallyDrop,
Expand Down Expand Up @@ -73,11 +76,11 @@ impl<T, const N: usize, const M: usize> From<[T; M]> for SmallVec<T, N> {
}
}

impl<T, const N: usize, const M: usize> TryFrom<SmallVec<T, N>> for [T; M] {
type Error = SmallVec<T, N>;
impl<T, const N: usize, const M: usize, A: Allocator> TryFrom<SmallVec<T, N, A>> for [T; M] {
type Error = SmallVec<T, N, A>;

#[inline]
fn try_from(mut this: SmallVec<T, N>) -> Result<[T; M], SmallVec<T, N>> {
fn try_from(mut this: SmallVec<T, N, A>) -> Result<[T; M], SmallVec<T, N, A>> {
if this.len() != M {
Err(this)
} else {
Expand Down
Loading