{"action":"created","issue":{"url":"https://api.github.com/repos/tailhook/quick-error/issues/13","labels_url":"https://api.github.com/repos/tailhook/quick-error/issues/13/labels{/name}","comments_url":"https://api.github.com/repos/tailhook/quick-error/issues/13/comments","events_url":"https://api.github.com/repos/tailhook/quick-error/issues/13/events","html_url":"https://github.com/tailhook/quick-error/issues/13","id":123982281,"number":13,"title":"Support access to std::fmt::Formatter inside display for more flexibility","user":{"login":"colin-kiegel","id":7691186,"avatar_url":"https://avatars.githubusercontent.com/u/7691186?v=3","gravatar_id":"","url":"https://api.github.com/users/colin-kiegel","html_url":"https://github.com/colin-kiegel","followers_url":"https://api.github.com/users/colin-kiegel/followers","following_url":"https://api.github.com/users/colin-kiegel/following{/other_user}","gists_url":"https://api.github.com/users/colin-kiegel/gists{/gist_id}","starred_url":"https://api.github.com/users/colin-kiegel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colin-kiegel/subscriptions","organizations_url":"https://api.github.com/users/colin-kiegel/orgs","repos_url":"https://api.github.com/users/colin-kiegel/repos","events_url":"https://api.github.com/users/colin-kiegel/events{/privacy}","received_events_url":"https://api.github.com/users/colin-kiegel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-27T14:57:04Z","updated_at":"2015-12-27T15:52:56Z","closed_at":null,"body":"It would be nice to implement display via direct access to the std::fmt::Formatter - as another option. This would allow additional logic inside the display logic without temporary buffers.\r\n\r\nUse case: Complex enum-variant with `Option<...>` fields.\r\n\r\nAt first I was thinking about closures, but this would require to capture all fields explicitly - not so nice. Instead I suggest we provide it like `display(f, me) -> { /* ... */ }`.\r\n\r\n**Suggested Grammar** (example)\r\n```rust\r\ndisplay(f, me) -> {\r\n    try!(write!(f, \"{} Expected token {:?} but found {:?} at {:?}.\",\r\n        me.description(), expected, found.token(), found.position()));\r\n\r\n    // additional logic\r\n\r\n    Ok(())\r\n}\r\n```\r\n\r\n**Current Workaround** - needs redundant allocation for temporary buffer\r\n```rust\r\ndisplay(me) -> (\"{buf}\", buf={\r\n    use std::fmt::Write;\r\n    let mut f = String::new()\r\n    write!(f, \"{} Expected token {:?} but found {:?} at {:?}.\",\r\n        me.description(), expected, found.token(), found.position()).unwrap();\r\n\r\n    // additional logic\r\n\r\n    f\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/tailhook/quick-error/issues/comments/167421344","html_url":"https://github.com/tailhook/quick-error/issues/13#issuecomment-167421344","issue_url":"https://api.github.com/repos/tailhook/quick-error/issues/13","id":167421344,"user":{"login":"colin-kiegel","id":7691186,"avatar_url":"https://avatars.githubusercontent.com/u/7691186?v=3","gravatar_id":"","url":"https://api.github.com/users/colin-kiegel","html_url":"https://github.com/colin-kiegel","followers_url":"https://api.github.com/users/colin-kiegel/followers","following_url":"https://api.github.com/users/colin-kiegel/following{/other_user}","gists_url":"https://api.github.com/users/colin-kiegel/gists{/gist_id}","starred_url":"https://api.github.com/users/colin-kiegel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colin-kiegel/subscriptions","organizations_url":"https://api.github.com/users/colin-kiegel/orgs","repos_url":"https://api.github.com/users/colin-kiegel/repos","events_url":"https://api.github.com/users/colin-kiegel/events{/privacy}","received_events_url":"https://api.github.com/users/colin-kiegel/received_events","type":"User","site_admin":false},"created_at":"2015-12-27T15:52:56Z","updated_at":"2015-12-27T15:52:56Z","body":"You are right about the argument order.\r\n\r\nThe purpose in this case would be to write some additional data only in some cases, like\r\n```rust\r\nif let Some(x) = reason {\r\n    try!(write!(f, \" {}\", x));\r\n}\r\n```\r\n\r\nAt least that was my use case - I agree, it is not super important."}}