shepmaster / snafu

Easily assign underlying errors into domain-specific errors while adding context
https://docs.rs/snafu/
Apache License 2.0
1.4k stars 60 forks source link

Customize `Location` debug output to remove `_other` #333

Closed shepmaster closed 2 years ago

shepmaster commented 2 years ago

It's noise and looking at the Debug format is pretty common for quick debugging.

hellow554 commented 2 years ago

What about using #[non_exhaustive] instead of _other? See https://stackoverflow.com/a/70965787/1021920 for more information 😜

Enet4 commented 2 years ago

The code itself seems to have that hint, but the current minimum tested version of Rust is 1.34. Unless we're OK with bumping this in the next version, we'll need to gate the presence of _other on a feature (rust_1_46 already exists) or just keep it regardless.

hellow554 commented 2 years ago

current minimum tested version of Rust is 1.34

Where do you get that information from? I can't find that in the readme or docs?

#[non_exhaustive] was introduced in 1.40 so rust_1_46 should be okay to use, I guess? Else one could use a build.rs file to determine the rust version and detect the rust version which then sets the feature flag automatically.

In the end, it should be relativly easy to adapt the Debug output, by using debug_struct even without using #[non_exhaustive]:

fmt.debug_struct("Location")
            .field("file", &self.file)
            .field("line", &self.line)
            .field("column", &self.column)
            .finish()

(btw. hello enet4 👋 :) )

Enet4 commented 2 years ago

current minimum tested version of Rust is 1.34

Where do you get that information from? I can't find that in the readme or docs?

It's in the compatibility page of the guide.

#[non_exhaustive] was introduced in 1.40 so rust_1_46 should be okay to use, I guess? Else one could use a build.rs file to determine the rust version and detect the rust version which then sets the feature flag automatically.

I wouldn't go as far as to use build scripts for this.

In the end, it should be relativly easy to adapt the Debug output, by using debug_struct even without using #[non_exhaustive]:

Sounds like you are ready to send in a PR. :)

(btw. hello enet4 👋 :) )

Hai 👋

8573 commented 2 years ago

https://github.com/dtolnay/rustversion could allow easily conditioning compilation on the Rust version without directly using a build script.