Skip to main content

edgefirst_tensor/
error.rs

1// SPDX-FileCopyrightText: Copyright 2025 Au-Zone Technologies
2// SPDX-License-Identifier: Apache-2.0
3
4pub type Result<T, E = Error> = std::result::Result<T, E>;
5
6#[derive(Debug)]
7pub enum Error {
8    IoError(std::io::Error),
9    #[cfg(unix)]
10    NixError(nix::Error),
11    NotImplemented(String),
12    InvalidSize(usize),
13    ShapeMismatch(String),
14    #[cfg(target_os = "linux")]
15    UnknownDeviceType(u64, u64),
16    InvalidMemoryType(String),
17    #[cfg(feature = "ndarray")]
18    NdArrayError(ndarray::ShapeError),
19}
20
21impl From<std::io::Error> for Error {
22    fn from(err: std::io::Error) -> Self {
23        Error::IoError(err)
24    }
25}
26#[cfg(unix)]
27impl From<nix::Error> for Error {
28    fn from(err: nix::Error) -> Self {
29        Error::NixError(err)
30    }
31}
32
33#[cfg(feature = "ndarray")]
34impl From<ndarray::ShapeError> for Error {
35    fn from(err: ndarray::ShapeError) -> Self {
36        Error::NdArrayError(err)
37    }
38}
39
40impl std::fmt::Display for Error {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        write!(f, "{self:?}")
43    }
44}
45
46impl std::error::Error for Error {}