Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Error as enum #45

Open
i1i1 opened this issue Dec 20, 2020 · 0 comments
Open

Implement Error as enum #45

i1i1 opened this issue Dec 20, 2020 · 0 comments

Comments

@i1i1
Copy link
Contributor

i1i1 commented Dec 20, 2020

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>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant