Skip to content
Closed
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
25 changes: 25 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

Comment on lines +1 to +6

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to include this, it can be removed

/// 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: alloc::alloc::Layout,
},
}

impl core::fmt::Display for CollectionAllocErr {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Allocation error: {:?}", self)
}
}

impl core::error::Error for CollectionAllocErr {}
22 changes: 3 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extern crate std;
mod borsh;
mod comparisons;
mod conversions;
mod errors;
mod macros;
#[cfg(feature = "malloc_size_of")]
mod mallocsizeof;
Expand All @@ -80,6 +81,8 @@ mod references;
mod serde;
mod taggedlen;

pub use errors::CollectionAllocErr;

#[cfg(feature = "bytes")]
use bytes::{
BufMut,
Expand Down Expand Up @@ -132,25 +135,6 @@ use {
taggedlen::TaggedLen
};

/// 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
}
}
impl core::fmt::Display for CollectionAllocErr {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "Allocation error: {:?}", self)
}
}

impl core::error::Error for CollectionAllocErr {}

#[inline]
fn infallible<T>(result: Result<T, CollectionAllocErr>) -> T {
match result {
Expand Down
Loading