async_tensorrt/
error.rs

1/// An error that occurred in TensorRT.
2#[derive(Debug, Clone)]
3pub enum Error {
4    /// TensorRT error described by error message.
5    TensorRt { message: String },
6    /// Error in CUDA backend.
7    Cuda(async_cuda::Error),
8}
9
10impl std::fmt::Display for Error {
11    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
12        match self {
13            Error::TensorRt { message } => write!(f, "{message}"),
14            Error::Cuda(err) => write!(f, "{err}"),
15        }
16    }
17}
18
19impl std::error::Error for Error {}
20
21impl From<async_cuda::Error> for Error {
22    #[inline]
23    fn from(err: async_cuda::Error) -> Self {
24        Error::Cuda(err)
25    }
26}
27
28/// Create a TensorRT error from the last recorded error produced by the logger.
29///
30/// # Thread-safety
31///
32/// This function might return an error that was produced by an invocation to some TensorRT function
33/// in a different thread.
34///
35/// # Return value
36///
37/// TensorRT error with corresponding error message.
38#[inline]
39pub(crate) fn last_error() -> Error {
40    Error::TensorRt {
41        message: crate::ffi::error::get_last_error_message(),
42    }
43}