Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
35 changes: 35 additions & 0 deletions crates/pina_pod_primitives/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Error type for Pod collection operations.

use core::fmt;

/// Error type for collection operations.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PodCollectionError {
/// Value exceeds capacity.
Overflow,
/// Invalid UTF-8 in string data.
InvalidUtf8,
/// Index out of bounds.
OutOfBounds,
}

impl fmt::Display for PodCollectionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Overflow => write!(f, "value exceeds capacity"),
Self::InvalidUtf8 => write!(f, "invalid UTF-8"),
Self::OutOfBounds => write!(f, "index out of bounds"),
}
}
}

/// Returns the maximum `N` value representable by a `PFX`-byte length prefix.
pub(crate) const fn max_n_for_pfx(pfx: usize) -> usize {
match pfx {
1 => u8::MAX as usize,
2 => u16::MAX as usize,
4 => u32::MAX as usize,
8 => usize::MAX,
_ => 0,
}
}
Loading
Loading