dtolnay / thiserror

derive(Error) for struct and enum error types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generating error variant description from doc string.

creativcoder opened this issue · comments

Hi @dtolnay

So, I have the following error:

pub enum Err {
    /// This is error one
    #[error("This is error one")]
    ErrorOne
}

which is exposed from my library.

Is there a way, I can write #[error(from_doc_string)] or something similar over ErrorOne which will generate the description from doc string itself? This way I don't have to type the same description twice.

This not something I want to build into thiserror, but you can use #[derive(thiserror::Error, displaydoc::Display)] together.
https://github.com/yaahc/displaydoc