From 8cf6efb62e9e547ab82d0e23c81f252c66c7d052 Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sat, 19 Sep 2026 12:50:19 +0200 Subject: [PATCH 01/11] refactor: new error system --- src/errors.rs | 97 ++++++++++++++++++++++++++++++++++++++++------ src/lib.rs | 64 ++++++++++++++---------------- src/rawsmallvec.rs | 20 +++++----- 3 files changed, 123 insertions(+), 58 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index d878ea70..eb70db4a 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,20 +1,93 @@ -use core::alloc::Layout; +use core::{ + alloc::Layout, + error::Error, + fmt::{ + Debug, + Display, + Formatter, + Result as Format + } +}; -/// Error type for APIs with fallible heap allocation #[derive(Debug)] -pub enum CollectionAllocErr { - /// Overflow `usize::MAX` or other error during size computation - CapacityOverflow, - /// The allocator return an error - AllocErr { - /// The layout that was passed to the allocator - layout: Layout +pub struct CapacityOverflow; + +impl Handle for CapacityOverflow { + type Handled = !; + + #[inline] + fn handle(self) -> Self::Handled { + panic!("capacity overflow") } } -impl core::fmt::Display for CollectionAllocErr { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + +impl Display for CapacityOverflow { + fn fmt(&self, f: &mut Formatter<'_>) -> Format { + write!(f, "Allocation error: {:?}", self) + } +} + +impl Error for CapacityOverflow {} + +#[derive(Debug)] +pub struct AllocationError(pub Layout); + +impl Handle for AllocationError { + type Handled = !; + + #[inline] + fn handle(self) -> Self::Handled { + alloc::alloc::handle_alloc_error(self.0) + } +} + +impl Display for AllocationError { + fn fmt(&self, f: &mut Formatter<'_>) -> Format { + write!(f, "Allocation error: {:?}", self) + } +} + +impl Error for AllocationError {} + +pub trait Handle { + type Handled; + fn handle(self) -> Self::Handled; +} + +impl> Handle for Result { + type Handled = Type; + + #[inline] + fn handle(self) -> Self::Handled { + match self { + Ok(value) => value, + Err(error) => error.handle() + } + } +} + +#[derive(Debug)] +pub enum SmallVecError { + CapacityOverflow(CapacityOverflow), + AllocationError(AllocationError) +} + +impl Handle for SmallVecError { + type Handled = !; + + #[inline] + fn handle(self) -> Self::Handled { + match self { + Self::CapacityOverflow(error) => error.handle(), + Self::AllocationError(error) => error.handle() + } + } +} + +impl Display for SmallVecError { + fn fmt(&self, f: &mut Formatter<'_>) -> Format { write!(f, "Allocation error: {:?}", self) } } -impl core::error::Error for CollectionAllocErr {} +impl Error for SmallVecError {} diff --git a/src/lib.rs b/src/lib.rs index 67634173..3c453b4c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,10 +52,15 @@ use defmt::{ Formatter as DeFormatter, write as dewrite }; -pub use errors::CollectionAllocErr; +pub use errors::{ + AllocationError, + CapacityOverflow, + SmallVecError +}; #[cfg(feature = "std")] use std::io; use { + crate::errors::Handle, alloc::{ boxed::Box, vec::Vec @@ -92,17 +97,6 @@ use { taggedlen::TaggedLen }; -#[inline] -fn infallible(result: Result) -> T { - match result { - Ok(x) => x, - Err(CollectionAllocErr::CapacityOverflow) => panic!("capacity overflow"), - Err(CollectionAllocErr::AllocErr { - layout - }) => alloc::alloc::handle_alloc_error(layout) - } -} - #[inline] /// A local copy of [`core::slice::range`]. The latter function is unstable /// and thus cannot be used yet. @@ -339,7 +333,7 @@ impl Drain<'_, T, N, A> { let result = vec.try_reserve(additional); // Restore the prefix length before a reservation error can panic. unsafe { vec.set_len(old_len) }; - infallible(result); + result.handle(); let new_tail_start = self.tail_start + additional; unsafe { @@ -630,7 +624,7 @@ impl SmallVec { Self::new_in(Global) } - pub fn try_with_capacity(capacity: usize) -> Result { + pub fn try_with_capacity(capacity: usize) -> Result { Self::try_with_capacity_in(capacity, Global) } @@ -1162,11 +1156,11 @@ impl SmallVec { #[inline] pub fn grow(&mut self, new_capacity: usize) { - infallible(self.try_grow(new_capacity)); + self.try_grow(new_capacity).handle(); } #[cold] - pub fn try_grow(&mut self, new_capacity: usize) -> Result<(), CollectionAllocErr> { + pub fn try_grow(&mut self, new_capacity: usize) -> Result<(), SmallVecError> { if Self::IS_ZST { return Ok(()); } @@ -1212,24 +1206,24 @@ impl SmallVec { pub fn reserve(&mut self, additional: usize) { // can't overflow since len <= capacity if additional > self.capacity() - self.len() { - let new_capacity = infallible( - self.len() - .checked_add(additional) - .and_then(usize::checked_next_power_of_two) - .ok_or(CollectionAllocErr::CapacityOverflow) - ); + let new_capacity = self + .len() + .checked_add(additional) + .and_then(usize::checked_next_power_of_two) + .ok_or(CapacityOverflow) + .handle(); self.grow(new_capacity); } } #[inline] - pub fn try_reserve(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { + pub fn try_reserve(&mut self, additional: usize) -> Result<(), SmallVecError> { if additional > self.capacity() - self.len() { let new_capacity = self .len() .checked_add(additional) .and_then(usize::checked_next_power_of_two) - .ok_or(CollectionAllocErr::CapacityOverflow)?; + .ok_or(SmallVecError::CapacityOverflow(CapacityOverflow))?; self.try_grow(new_capacity) } else { Ok(()) @@ -1240,22 +1234,22 @@ impl SmallVec { pub fn reserve_exact(&mut self, additional: usize) { // can't overflow since len <= capacity if additional > self.capacity() - self.len() { - let new_capacity = infallible( - self.len() - .checked_add(additional) - .ok_or(CollectionAllocErr::CapacityOverflow) - ); + let new_capacity = self + .len() + .checked_add(additional) + .ok_or(CapacityOverflow) + .handle(); self.grow(new_capacity); } } #[inline] - pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), CollectionAllocErr> { + pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), SmallVecError> { if additional > self.capacity() - self.len() { let new_capacity = self .len() .checked_add(additional) - .ok_or(CollectionAllocErr::CapacityOverflow)?; + .ok_or(SmallVecError::CapacityOverflow(CapacityOverflow))?; self.try_grow(new_capacity) } else { Ok(()) @@ -1283,7 +1277,7 @@ impl SmallVec { // SAFETY: len > Self::inline_size() >= 0 // so new capacity is non zero, it is equal to the length // T can't be a ZST because SmallVec is never spilled. - unsafe { infallible(self.raw.try_grow_raw(self.len, len)) }; + unsafe { self.raw.try_grow_raw(self.len, len).handle() }; } } @@ -1315,7 +1309,7 @@ impl SmallVec { // SAFETY: len > Self::inline_size() >= 0 // so new capacity is non zero, it is equal to the length // T can't be a ZST because SmallVec is never spilled. - unsafe { infallible(self.raw.try_grow_raw(self.len, target)) }; + unsafe { self.raw.try_grow_raw(self.len, target).handle() }; } } } @@ -1864,7 +1858,7 @@ impl SmallVec { } } - pub fn try_with_capacity_in(capacity: usize, alloc: A) -> Result { + pub fn try_with_capacity_in(capacity: usize, alloc: A) -> Result { let mut this = Self::new_in(alloc); if capacity > Self::inline_size() && !Self::IS_ZST { // SAFETY: we checked all the preconditions @@ -1877,7 +1871,7 @@ impl SmallVec { } pub fn with_capacity_in(capacity: usize, alloc: A) -> Self { - infallible(Self::try_with_capacity_in(capacity, alloc)) + Self::try_with_capacity_in(capacity, alloc).handle() } } diff --git a/src/rawsmallvec.rs b/src/rawsmallvec.rs index 9a359af7..e468a723 100644 --- a/src/rawsmallvec.rs +++ b/src/rawsmallvec.rs @@ -1,7 +1,9 @@ use { super::{ + AllocationError, Allocator, - CollectionAllocErr, + CapacityOverflow, + SmallVecError, taggedlen::TaggedLen }, core::{ @@ -122,7 +124,7 @@ impl RawSmallVec { &mut self, len: TaggedLen, new_capacity: usize - ) -> Result<(), CollectionAllocErr> { + ) -> Result<(), SmallVecError> { let (len, was_on_heap) = len.parts(); debug_assert!(!Self::IS_ZST); debug_assert!(new_capacity > 0 && new_capacity >= len); @@ -130,10 +132,10 @@ impl RawSmallVec { // SAFETY: the tag tells which member is active let ptr = unsafe { self.as_mut_ptr(was_on_heap) }; - let new_layout = - Layout::array::(new_capacity).map_err(|_| CollectionAllocErr::CapacityOverflow)?; + let new_layout = Layout::array::(new_capacity) + .map_err(|_| SmallVecError::CapacityOverflow(CapacityOverflow))?; if new_layout.size() > isize::MAX as usize { - return Err(CollectionAllocErr::CapacityOverflow); + return Err(SmallVecError::CapacityOverflow(CapacityOverflow)); } let new_ptr = if !was_on_heap { @@ -142,9 +144,7 @@ impl RawSmallVec { let new_ptr = self .alloc .allocate(new_layout) - .map_err(|_| CollectionAllocErr::AllocErr { - layout: new_layout - })? + .map_err(|_| SmallVecError::AllocationError(AllocationError(new_layout)))? .cast(); unsafe { copy_nonoverlapping(ptr, new_ptr.as_ptr(), len) }; new_ptr @@ -178,9 +178,7 @@ impl RawSmallVec { new_layout ) } - .map_err(|_| CollectionAllocErr::AllocErr { - layout: new_layout - })? + .map_err(|_| SmallVecError::AllocationError(AllocationError(new_layout)))? .cast() }; self.inner.heap = (new_ptr, new_capacity); From 7864d3e8772db382ee6fa6695c9474625c4b1618 Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sat, 19 Sep 2026 12:56:18 +0200 Subject: [PATCH 02/11] fix: remove never type --- src/errors.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index eb70db4a..a16aba93 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -9,11 +9,13 @@ use core::{ } }; +pub enum Never {} + #[derive(Debug)] pub struct CapacityOverflow; impl Handle for CapacityOverflow { - type Handled = !; + type Handled = Never; #[inline] fn handle(self) -> Self::Handled { @@ -33,7 +35,7 @@ impl Error for CapacityOverflow {} pub struct AllocationError(pub Layout); impl Handle for AllocationError { - type Handled = !; + type Handled = Never; #[inline] fn handle(self) -> Self::Handled { @@ -54,14 +56,15 @@ pub trait Handle { fn handle(self) -> Self::Handled; } -impl> Handle for Result { +impl> Handle for Result { type Handled = Type; #[inline] fn handle(self) -> Self::Handled { match self { Ok(value) => value, - Err(error) => error.handle() + #[allow(unused)] + Err(error) => match error.handle() {} } } } @@ -73,7 +76,7 @@ pub enum SmallVecError { } impl Handle for SmallVecError { - type Handled = !; + type Handled = Never; #[inline] fn handle(self) -> Self::Handled { From 4c5cd97ec9c5b343667b891c57ae1a1e449606d1 Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sat, 19 Sep 2026 12:56:59 +0200 Subject: [PATCH 03/11] fix: precise lint --- src/errors.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/errors.rs b/src/errors.rs index a16aba93..1e380bbb 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -63,7 +63,7 @@ impl> Handle for Result { fn handle(self) -> Self::Handled { match self { Ok(value) => value, - #[allow(unused)] + #[allow(unreachable_code)] Err(error) => match error.handle() {} } } From 7ba78148169eef72c0f983716972a4aa9d69a709 Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sat, 19 Sep 2026 13:32:53 +0200 Subject: [PATCH 04/11] refactor: change to infallible --- src/errors.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 1e380bbb..0770c2fd 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -6,16 +6,15 @@ use core::{ Display, Formatter, Result as Format - } + }, + convert::Infallible }; -pub enum Never {} - #[derive(Debug)] pub struct CapacityOverflow; impl Handle for CapacityOverflow { - type Handled = Never; + type Handled = Infallible; #[inline] fn handle(self) -> Self::Handled { @@ -35,7 +34,7 @@ impl Error for CapacityOverflow {} pub struct AllocationError(pub Layout); impl Handle for AllocationError { - type Handled = Never; + type Handled = Infallible; #[inline] fn handle(self) -> Self::Handled { @@ -56,7 +55,7 @@ pub trait Handle { fn handle(self) -> Self::Handled; } -impl> Handle for Result { +impl> Handle for Result { type Handled = Type; #[inline] @@ -76,7 +75,7 @@ pub enum SmallVecError { } impl Handle for SmallVecError { - type Handled = Never; + type Handled = Infallible; #[inline] fn handle(self) -> Self::Handled { From 9553b24712d35ffe6ea0dc4d298b8e9cf9f0bc10 Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sat, 19 Sep 2026 13:34:25 +0200 Subject: [PATCH 05/11] fix: style formatting --- src/errors.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 0770c2fd..99d9e1e4 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,13 +1,13 @@ use core::{ alloc::Layout, + convert::Infallible, error::Error, fmt::{ Debug, Display, Formatter, Result as Format - }, - convert::Infallible + } }; #[derive(Debug)] From fb2e81841adbe40b0accd8d206a80a07e92ef2b6 Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sat, 19 Sep 2026 13:56:29 +0200 Subject: [PATCH 06/11] refactor: include in-string formatting --- src/errors.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 99d9e1e4..5c1d9dc4 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -24,7 +24,7 @@ impl Handle for CapacityOverflow { impl Display for CapacityOverflow { fn fmt(&self, f: &mut Formatter<'_>) -> Format { - write!(f, "Allocation error: {:?}", self) + write!(f, "Allocation error: {self:?}") } } @@ -44,7 +44,7 @@ impl Handle for AllocationError { impl Display for AllocationError { fn fmt(&self, f: &mut Formatter<'_>) -> Format { - write!(f, "Allocation error: {:?}", self) + write!(f, "Allocation error: {self:?}") } } @@ -88,7 +88,7 @@ impl Handle for SmallVecError { impl Display for SmallVecError { fn fmt(&self, f: &mut Formatter<'_>) -> Format { - write!(f, "Allocation error: {:?}", self) + write!(f, "Allocation error: {self:?}") } } From 56a6eb938ec403e1cd2ab6d244adeca807d10462 Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sun, 20 Sep 2026 11:41:03 +0200 Subject: [PATCH 07/11] fix: error handling --- src/iterators/drain.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/iterators/drain.rs b/src/iterators/drain.rs index 8731d7c6..bc098b47 100644 --- a/src/iterators/drain.rs +++ b/src/iterators/drain.rs @@ -1,7 +1,7 @@ use crate::{ Allocator, SmallVec, - infallible + errors::Handle }; /// An iterator that removes the items from a `SmallVec` and yields them by @@ -180,7 +180,7 @@ impl Drain<'_, T, N, A> { let result = vec.try_reserve(additional); // Restore the prefix length before a reservation error can panic. unsafe { vec.set_len(old_len) }; - infallible(result); + result.handle(); let new_tail_start = self.tail_start + additional; unsafe { From e5c0c9667012a7f99f5c3786013dbd1f247a1f4c Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sun, 20 Sep 2026 11:56:15 +0200 Subject: [PATCH 08/11] fix: remove crate import prefix --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 476c13e2..49c6ada0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,6 @@ pub use errors::{ #[cfg(feature = "std")] use std::io; use { - crate::errors::Handle, alloc::{ boxed::Box, vec::Vec @@ -85,7 +84,8 @@ use { copy_nonoverlapping, drop_in_place } - } + }, + errors::Handle }; #[cfg(feature = "internals")] pub use { From cbd561391c95057fcee158d1d8300cc9abecda61 Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sun, 20 Sep 2026 13:59:00 +0200 Subject: [PATCH 09/11] refactor: simplified errors --- src/errors.rs | 102 +++++++++++---------------------------------- src/lib.rs | 14 +++---- src/rawsmallvec.rs | 10 ++--- 3 files changed, 34 insertions(+), 92 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 5c1d9dc4..c9bce449 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,90 +1,29 @@ -use core::{ - alloc::Layout, - convert::Infallible, - error::Error, - fmt::{ - Debug, - Display, - Formatter, - Result as Format - } +use { + core::{ + alloc::Layout, + error::Error, + fmt::{ + Debug, + Display, + Formatter, + Result as Format + } + }, + alloc::alloc::handle_alloc_error }; -#[derive(Debug)] -pub struct CapacityOverflow; - -impl Handle for CapacityOverflow { - type Handled = Infallible; - - #[inline] - fn handle(self) -> Self::Handled { - panic!("capacity overflow") - } -} - -impl Display for CapacityOverflow { - fn fmt(&self, f: &mut Formatter<'_>) -> Format { - write!(f, "Allocation error: {self:?}") - } -} - -impl Error for CapacityOverflow {} - -#[derive(Debug)] -pub struct AllocationError(pub Layout); - -impl Handle for AllocationError { - type Handled = Infallible; - - #[inline] - fn handle(self) -> Self::Handled { - alloc::alloc::handle_alloc_error(self.0) - } -} - -impl Display for AllocationError { - fn fmt(&self, f: &mut Formatter<'_>) -> Format { - write!(f, "Allocation error: {self:?}") - } -} - -impl Error for AllocationError {} - pub trait Handle { type Handled; fn handle(self) -> Self::Handled; } -impl> Handle for Result { - type Handled = Type; - - #[inline] - fn handle(self) -> Self::Handled { - match self { - Ok(value) => value, - #[allow(unreachable_code)] - Err(error) => match error.handle() {} - } - } -} - #[derive(Debug)] pub enum SmallVecError { - CapacityOverflow(CapacityOverflow), - AllocationError(AllocationError) + CapacityOverflow, + AllocationError(Layout) } -impl Handle for SmallVecError { - type Handled = Infallible; - - #[inline] - fn handle(self) -> Self::Handled { - match self { - Self::CapacityOverflow(error) => error.handle(), - Self::AllocationError(error) => error.handle() - } - } -} +impl Error for SmallVecError {} impl Display for SmallVecError { fn fmt(&self, f: &mut Formatter<'_>) -> Format { @@ -92,4 +31,13 @@ impl Display for SmallVecError { } } -impl Error for SmallVecError {} +impl Handle for Result { + type Handled = Type; + fn handle(self) -> Self::Handled { + match self { + Ok(value) => value, + Err(SmallVecError::CapacityOverflow) => panic!("smallvec capacity overflow"), + Err(SmallVecError::AllocationError(layout)) => handle_alloc_error(layout) + } + } +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 49c6ada0..3bf8a930 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,11 +53,7 @@ use defmt::{ Formatter as DeFormatter, write as dewrite }; -pub use errors::{ - AllocationError, - CapacityOverflow, - SmallVecError -}; +pub use errors::SmallVecError; #[cfg(feature = "std")] use std::io; use { @@ -1020,7 +1016,7 @@ impl SmallVec { .len() .checked_add(additional) .and_then(usize::checked_next_power_of_two) - .ok_or(CapacityOverflow) + .ok_or(SmallVecError::CapacityOverflow) .handle(); self.grow(new_capacity); } @@ -1033,7 +1029,7 @@ impl SmallVec { .len() .checked_add(additional) .and_then(usize::checked_next_power_of_two) - .ok_or(SmallVecError::CapacityOverflow(CapacityOverflow))?; + .ok_or(SmallVecError::CapacityOverflow)?; self.try_grow(new_capacity) } else { Ok(()) @@ -1047,7 +1043,7 @@ impl SmallVec { let new_capacity = self .len() .checked_add(additional) - .ok_or(CapacityOverflow) + .ok_or(SmallVecError::CapacityOverflow) .handle(); self.grow(new_capacity); } @@ -1059,7 +1055,7 @@ impl SmallVec { let new_capacity = self .len() .checked_add(additional) - .ok_or(SmallVecError::CapacityOverflow(CapacityOverflow))?; + .ok_or(SmallVecError::CapacityOverflow)?; self.try_grow(new_capacity) } else { Ok(()) diff --git a/src/rawsmallvec.rs b/src/rawsmallvec.rs index e468a723..0981e10a 100644 --- a/src/rawsmallvec.rs +++ b/src/rawsmallvec.rs @@ -1,8 +1,6 @@ use { super::{ - AllocationError, Allocator, - CapacityOverflow, SmallVecError, taggedlen::TaggedLen }, @@ -133,9 +131,9 @@ impl RawSmallVec { let ptr = unsafe { self.as_mut_ptr(was_on_heap) }; let new_layout = Layout::array::(new_capacity) - .map_err(|_| SmallVecError::CapacityOverflow(CapacityOverflow))?; + .map_err(|_| SmallVecError::CapacityOverflow)?; if new_layout.size() > isize::MAX as usize { - return Err(SmallVecError::CapacityOverflow(CapacityOverflow)); + return Err(SmallVecError::CapacityOverflow); } let new_ptr = if !was_on_heap { @@ -144,7 +142,7 @@ impl RawSmallVec { let new_ptr = self .alloc .allocate(new_layout) - .map_err(|_| SmallVecError::AllocationError(AllocationError(new_layout)))? + .map_err(|_| SmallVecError::AllocationError(new_layout))? .cast(); unsafe { copy_nonoverlapping(ptr, new_ptr.as_ptr(), len) }; new_ptr @@ -178,7 +176,7 @@ impl RawSmallVec { new_layout ) } - .map_err(|_| SmallVecError::AllocationError(AllocationError(new_layout)))? + .map_err(|_| SmallVecError::AllocationError(new_layout))? .cast() }; self.inner.heap = (new_ptr, new_capacity); From 35321b24e3d3664c4f84495fc0ccc10164e81fb7 Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sun, 20 Sep 2026 13:59:33 +0200 Subject: [PATCH 10/11] refactor: add handle inline --- src/errors.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/errors.rs b/src/errors.rs index c9bce449..38149078 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -33,6 +33,7 @@ impl Display for SmallVecError { impl Handle for Result { type Handled = Type; + #[inline] fn handle(self) -> Self::Handled { match self { Ok(value) => value, From 1852ed3c8325614c2deff73a9c52392c30fe932b Mon Sep 17 00:00:00 2001 From: Alejandro Vaz Date: Sun, 20 Sep 2026 14:00:41 +0200 Subject: [PATCH 11/11] style: formatting --- src/errors.rs | 7 ++++--- src/rawsmallvec.rs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/errors.rs b/src/errors.rs index 38149078..a053efa6 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,4 +1,5 @@ use { + alloc::alloc::handle_alloc_error, core::{ alloc::Layout, error::Error, @@ -8,8 +9,7 @@ use { Formatter, Result as Format } - }, - alloc::alloc::handle_alloc_error + } }; pub trait Handle { @@ -33,6 +33,7 @@ impl Display for SmallVecError { impl Handle for Result { type Handled = Type; + #[inline] fn handle(self) -> Self::Handled { match self { @@ -41,4 +42,4 @@ impl Handle for Result { Err(SmallVecError::AllocationError(layout)) => handle_alloc_error(layout) } } -} \ No newline at end of file +} diff --git a/src/rawsmallvec.rs b/src/rawsmallvec.rs index 0981e10a..c70d9aa2 100644 --- a/src/rawsmallvec.rs +++ b/src/rawsmallvec.rs @@ -130,8 +130,8 @@ impl RawSmallVec { // SAFETY: the tag tells which member is active let ptr = unsafe { self.as_mut_ptr(was_on_heap) }; - let new_layout = Layout::array::(new_capacity) - .map_err(|_| SmallVecError::CapacityOverflow)?; + let new_layout = + Layout::array::(new_capacity).map_err(|_| SmallVecError::CapacityOverflow)?; if new_layout.size() > isize::MAX as usize { return Err(SmallVecError::CapacityOverflow); }