Skip to content

Implement Error as enum #45

@i1i1

Description

@i1i1

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>;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions