Skip to main content

draco_core/
status.rs

1use thiserror::Error;
2
3/// Error returned by Draco decoding, encoding, and data model operations.
4#[derive(Error, Debug, Clone, PartialEq)]
5pub enum DracoError {
6    /// Generic Draco error with a human-readable message.
7    #[error("General error: {0}")]
8    DracoError(String),
9    /// File or stream I/O error.
10    #[error("IO error: {0}")]
11    IoError(String),
12    /// Invalid caller-provided parameter.
13    #[error("Invalid parameter: {0}")]
14    InvalidParameter(String),
15    /// Bitstream version is known but unsupported.
16    #[error("Unsupported version: {0}")]
17    UnsupportedVersion(String),
18    /// Bitstream version could not be identified.
19    #[error("Unknown version: {0}")]
20    UnknownVersion(String),
21    /// Bitstream uses a feature this crate does not support.
22    #[error("Unsupported feature: {0}")]
23    UnsupportedFeature(String),
24    /// Bitstream version is outside the supported range.
25    #[error("Bitstream version unsupported")]
26    BitstreamVersionUnsupported,
27    /// Buffer read or write failed.
28    #[error("Buffer decode error: {0}")]
29    BufferError(String),
30}
31
32/// Convenience result type for operations that only report success or failure.
33pub type Status = Result<(), DracoError>;
34
35impl From<()> for DracoError {
36    fn from(_: ()) -> Self {
37        DracoError::DracoError("Unknown error".to_string())
38    }
39}
40
41/// Returns a successful [`Status`].
42pub fn ok_status() -> Status {
43    Ok(())
44}
45
46/// Creates a generic [`DracoError`] from a message.
47pub fn error_status(msg: impl Into<String>) -> DracoError {
48    DracoError::DracoError(msg.into())
49}