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

Optimize "{0}" and "{var}" to not require write! #13

Closed
dtolnay opened this issue Oct 11, 2019 · 1 comment
Closed

Optimize "{0}" and "{var}" to not require write! #13

dtolnay opened this issue Oct 11, 2019 · 1 comment

Comments

@dtolnay
Copy link
Owner

dtolnay commented Oct 11, 2019

#12 called out that the generated code from "{0}" is messier than just a Display::fmt(_0, formatter). I don't know why write! doesn't handle this case better, but we might as well do it in thiserror.

#[derive(Error, Debug)]
pub enum ParseFromEnvError {
    #[error("{0}")]
    InvalidLogFormat(io::Error),
}

^ Should expand the Display impl to:

  match self {
-     ParseFromEnvError::InvalidLogFormat(_0) => write!(formatter, "{}", _0),
+     ParseFromEnvError::InvalidLogFormat(_0) => Display::fmt(_0, formatter),
  }

@MOZGIII

@MOZGIII
Copy link

MOZGIII commented Oct 11, 2019

This definetly does the right thing. I still don't like #[error("{0}")] though. How about adding #[error_proxy] or something of that sort?

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

2 participants