Skip to main content

apple_mpsgraph/
error.rs

1/// Mirrors the `MPSGraph` framework counterpart for `Result`.
2pub type Result<T> = core::result::Result<T, Error>;
3
4/// Mirrors the `MPSGraph` framework counterpart for `Error`.
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub enum Error {
7/// Mirrors the `MPSGraph` framework case `InvalidLength`.
8    InvalidLength { expected: usize, actual: usize },
9/// Mirrors the `MPSGraph` framework case `OperationFailed`.
10    OperationFailed(&'static str),
11/// Mirrors the `MPSGraph` framework case `UnsupportedDataType`.
12    UnsupportedDataType(u32),
13}
14
15impl core::fmt::Display for Error {
16    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
17        match self {
18            Self::InvalidLength { expected, actual } => {
19                write!(
20                    f,
21                    "invalid buffer length: expected {expected} bytes, got {actual}"
22                )
23            }
24            Self::OperationFailed(message) => f.write_str(message),
25            Self::UnsupportedDataType(data_type) => {
26                write!(f, "unsupported MPSDataType raw value: {data_type:#x}")
27            }
28        }
29    }
30}
31
32impl std::error::Error for Error {}