tensorrt-rs
tensorrt-rs copied to clipboard
Implement Error as enum
Hello, as I've seen here Error now is anyhow::Error
.
As description at crates.io of it suggest:
This library provides anyhow::Error, a trait object based error type for easy idiomatic error handling in Rust applications.
Generally it is nice to use it for applications in order to merge all errors into 1 Error type and have good way to have context of some errors, but it is not great for libraries.
As a solution it's better just to use an enum or just struct(String). That will give some context of Error to caller. As an example from here:
/// Error which happened in cuda runtime
/// Todo: make it as enum
#[derive(Debug, Error, Clone)
pub struct CudaError(String);
/// Error which occured during inference
#[derive(Debug, Error, Clone)
pub struct InferenceError(pub CudaError);
impl From<CudaError> for InferenceError {
fn from(e: CudaError) -> Self {
Self(e)
}
}
impl Context {
pub fn execute<D1: Dimension, D2: Dimension>(
&self,
input_data: ExecuteInput<D1>,
mut output_data: Vec<ExecuteInput<D2>>,
) -> Result<(), InferenceError>;
}