Skip to main content

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 arithmetic operation (e.g. buffer sizing) would overflow.
15   /// 算术运算(如缓冲区大小计算)会溢出。
16   Overflow,
17   /// A buffer length does not match its declared dimensions.
18   /// 缓冲区长度与其声明的维度不匹配。
19   BufferMismatch,
20   /// Input data is structurally invalid (empty mesh, non-triangle count, etc.).
21   /// 输入数据在结构上无效(空网格、非三角形的顶点数等)。
22   InvalidData,
23   /// The input is a recognized format that this build does not support (e.g. an image format compiled out by a feature).
24   /// 输入是一种已识别、但当前构建不支持的格式(例如被某个特性编译掉的图像格式)。
25   UnsupportedFormat,
26}
27
28impl fmt::Display for Error {
29   fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30      let message = match self {
31         Error::InvalidSize => "invalid size or dimension",
32         Error::Overflow => "arithmetic overflow",
33         Error::BufferMismatch => "buffer length does not match declared dimensions",
34         Error::InvalidData => "malformed or invalid input data",
35         Error::UnsupportedFormat => "recognized but unsupported input format",
36      };
37      f.write_str(message)
38   }
39}
40
41#[cfg(feature = "std")]
42impl std::error::Error for Error {}