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