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

Improve Result's Display impl for extension values #424

Merged
merged 1 commit into from
Apr 27, 2021

Conversation

theo3
Copy link
Contributor

@theo3 theo3 commented Apr 26, 2021

Previously, the Display impl for vk::Result did not include handling for extension values. For example, VK_ERROR_OUT_OF_DATE_KHR would display simply as "-1000001004".

With this change, we fall back to the Debug impl of the Result if the value is unknown (i.e. from an extension). This preserves the current nice messages for non-extension values, and the numeric output for truly unknown values, but displays the enum variant name (e.g. "ERROR_OUT_OF_DATE_KHR") for extension-provided enum variants.

@theo3 theo3 force-pushed the master branch 2 times, most recently from cc37e66 to 538fecf Compare April 26, 2021 14:30
Copy link
Collaborator

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a much smarter way to go about this! Would you mind adding a comment clarifying that this forwards the call to the Debug printer generated for all enum variants in const_debugs.rs? Thanks!

(And indeed, if that printer doesn't know the enum variant either it'll finally fall back to self.0.fmt(fmt) again 👍 )

generator/src/lib.rs Outdated Show resolved Hide resolved
MarijnS95 added a commit that referenced this pull request Apr 27, 2021
The docs clearly state:

    #[rustc_deprecated(since = "1.42.0", reason = "use the Display impl or to_string()")]
    fn description(&self) -> &str {
        "description() is deprecated; use Display"
    }

We already have a `Display` implementation containing an identical
`match` block and has further improvements on the way in [1].

[1]: #424
Previously, the `Display` impl for `vk::Result` did not include handling
for extension values. For example, VK_ERROR_OUT_OF_DATE_KHR would
display simply as "-1000001004". Now, we fall back to the `Debug` impl
of the `Result` if the value is unknown (i.e. from an extension). This
preserves the current nice messages for non-extension values, and the
numeric output for truly unknown values, but displays the enum variant
name (e.g. "ERROR_OUT_OF_DATE")  for extension values.
@MarijnS95
Copy link
Collaborator

@theo3 Awesome, thanks! Merging as soon as the CI succeeds.

@MarijnS95 MarijnS95 merged commit d4f50bd into ash-rs:master Apr 27, 2021
MarijnS95 added a commit that referenced this pull request Apr 27, 2021
The docs clearly state:

    #[rustc_deprecated(since = "1.42.0", reason = "use the Display impl or to_string()")]
    fn description(&self) -> &str {
        "description() is deprecated; use Display"
    }

We already have a `Display` implementation containing an identical
`match` block and has further improvements on the way in [1].

[1]: #424
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

Successfully merging this pull request may close these issues.

2 participants