he3d_core/error.rs
1use core::fmt;
2
3/// Errors produced by core construction and validation paths.
4/// 核心构造与校验路径产生的错误。
5///
6/// Construction uses `checked_*` arithmetic and explicit limits, so oversized or malformed inputs return an error instead of overflowing or panicking.
7/// 构造使用 `checked_*` 算术和显式限制,因此过大或畸形的输入会返回错误,而不是溢出或 panic。
8#[derive(Clone, Copy, PartialEq, Eq, Debug)]
9#[non_exhaustive]
10pub enum Error {
11 /// A dimension or size is zero, negative, or exceeds a configured limit.
12 /// 维度或大小为 0、为负,或超过配置的限制。
13 InvalidSize,
14 /// An index falls outside the valid range.
15 /// 索引超出有效范围。
16 InvalidIndex,
17 /// An arithmetic operation (e.g. buffer sizing) would overflow.
18 /// 算术运算(如缓冲区大小计算)会溢出。
19 Overflow,
20 /// A buffer length does not match its declared dimensions.
21 /// 缓冲区长度与其声明的维度不匹配。
22 BufferMismatch,
23 /// Input data is structurally invalid (empty mesh, non-triangle count, etc.).
24 /// 输入数据在结构上无效(空网格、非三角形的顶点数等)。
25 InvalidData,
26 /// The input is a recognized format that this build does not support (e.g. an image format compiled out by a feature).
27 /// 输入是一种已识别、但当前构建不支持的格式(例如被某个特性编译掉的图像格式)。
28 UnsupportedFormat,
29}
30
31impl fmt::Display for Error {
32 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33 let message = match self {
34 Error::InvalidSize => "invalid size or dimension",
35 Error::InvalidIndex => "index out of bounds",
36 Error::Overflow => "arithmetic overflow",
37 Error::BufferMismatch => "buffer length does not match declared dimensions",
38 Error::InvalidData => "malformed or invalid input data",
39 Error::UnsupportedFormat => "recognized but unsupported input format",
40 };
41 f.write_str(message)
42 }
43}
44
45#[cfg(feature = "std")]
46impl std::error::Error for Error {}