display_derive
display_derive copied to clipboard
Allow arbitrary expressions
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)
Looks like stringifying the expression is the approach that structopt uses.