Skip to main content

molgfx_geometry/packing/
error.rs

1//! Typed failures produced before GPU records are emitted.
2
3use molgfx_core::EntityIdError;
4use std::fmt;
5
6/// A source row or compacted offset cannot be represented without aliasing.
7#[derive(Clone, Copy, PartialEq, Eq, Debug)]
8pub enum PackingError {
9    /// A picking identity exceeded the chunk-local attachment limit.
10    Entity(EntityIdError),
11    /// A CPU offset exceeded the GPU index width.
12    IndexOverflow {
13        /// Table or buffer being indexed.
14        resource: &'static str,
15        /// Rejected offset.
16        index: u64,
17    },
18}
19
20impl From<EntityIdError> for PackingError {
21    fn from(error: EntityIdError) -> Self {
22        Self::Entity(error)
23    }
24}
25
26impl fmt::Display for PackingError {
27    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
28        match self {
29            Self::Entity(error) => error.fmt(formatter),
30            Self::IndexOverflow { resource, index } => {
31                write!(
32                    formatter,
33                    "{resource} index {index} exceeds the GPU u32 limit"
34                )
35            }
36        }
37    }
38}
39
40impl std::error::Error for PackingError {}