Arnavion / derive-error-chain

A Macros 1.1 implementation of https://crates.io/crates/error-chain
19 stars 1 forks source link

Add `const("some string literal")` as a shorthand for `description()` #6

Closed Arnavion closed 6 years ago

Arnavion commented 7 years ago

As a workaround, one can use a closure instead of a function path:

#[derive(Debug, error_chain)]
pub enum ErrorKind {
    Msg(String),

    #[error_chain(custom, description = "http_status_description")]
    HttpStatus(u32),
}

fn http_status_description(_: &u32) -> &str {
    "http request returned an unsuccessful status code"
}

can be written as

#[derive(Debug, error_chain)]
pub enum ErrorKind {
    Msg(String),

    #[error_chain(custom)]
    #[error_chain(description = r#"(|_| "http request returned an unsuccessful status code")"#)]
    HttpStatus(u32),
}
Arnavion commented 7 years ago

Will be possible with upcoming #![feature(proc_macro)] enhancements (syn_0_12 branch).

Arnavion commented 7 years ago

This is implemented in the syn_0_12 branch, but the requirement of #[feature(proc_macro)] and syn v0.12 means this is probably not going to be in v0.11.0