display_derive icon indicating copy to clipboard operation
display_derive copied to clipboard

Allow arbitrary expressions

Open remexre opened this issue 6 years ago • 1 comments

This'd make the ergonomics around (at a minimum) PathBuf a lot nicer; right now:

#[derive(Debug, Fail)]
pub enum Error {
    /// An error opening a source file.
    #[fail(display = "Couldn't open `{:?}': {}", _0, _1)]
    CouldntOpenSource(PathBuf, IoError),

    // ...
}

doesn't work, since PathBuf: !Display.

#[fail(display = "Couldn't open `{:?}': {}", _0.display(), _1)]

doesn't work, since attributes can't contain arbitrary expressions.

#[fail(display = "Couldn't open `{:?}': {}", "_0.display()", _1)]

doesn't work, but could?

(Moved from https://github.com/rust-lang-nursery/failure/issues/183)

remexre avatar Mar 12 '18 09:03 remexre

Looks like stringifying the expression is the approach that structopt uses.

euclio avatar May 24 '18 20:05 euclio