Skip to main content

meshoptimizer_rs/
error.rs

1use core::fmt;
2
3/// Checked input, resource, allocation, or numerical failure.
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum Error {
7    /// A triangle list does not contain a multiple of three indices.
8    InvalidTopology,
9    /// An index does not identify a supplied vertex.
10    IndexOutOfBounds,
11    /// A vertex view has an invalid stride, width, offset, or length.
12    InvalidLayout,
13    /// A parameter is outside the operation's supported domain.
14    InvalidParameter,
15    /// A vertex flag or option mask contains unknown or unsupported bits.
16    UnknownFlags,
17    /// A codec version is unsupported.
18    UnsupportedVersion,
19    /// A caller destination is too small.
20    BufferTooSmall,
21    /// An encoded stream is malformed.
22    InvalidStream,
23    /// Size arithmetic or a platform allocation bound overflowed.
24    SizeOverflow,
25    /// The per-call storage or counted-work limit was exceeded.
26    LimitExceeded,
27    /// A fallible allocation failed.
28    AllocationFailed,
29    /// Geometry or an intermediate calculation is non-finite.
30    NumericalFailure,
31    /// An output vertex index cannot fit the requested index width.
32    IndexOverflow,
33}
34
35impl fmt::Display for Error {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        f.write_str(match self {
38            Self::IndexOverflow => "output index does not fit index width",
39            Self::InvalidTopology => "invalid triangle topology",
40            Self::IndexOutOfBounds => "vertex index out of bounds",
41            Self::InvalidLayout => "invalid vertex layout",
42            Self::InvalidParameter => "invalid parameter",
43            Self::UnknownFlags => "unknown or unsupported flag bits",
44            Self::UnsupportedVersion => "unsupported stream version",
45            Self::BufferTooSmall => "destination buffer too small",
46            Self::InvalidStream => "invalid encoded stream",
47            Self::SizeOverflow => "size overflow",
48            Self::LimitExceeded => "resource limit exceeded",
49            Self::AllocationFailed => "allocation failed",
50            Self::NumericalFailure => "non-finite geometry or calculation",
51        })
52    }
53}
54
55#[cfg(feature = "std")]
56impl std::error::Error for Error {}