-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
format!() ignores precision while formatting Debug #55584
Comments
I'd say this is not a bug.
// The behavior proposed here would change this to "0.12343"
assert_eq!(format!("{:.7?}", 0.1234321111), "0.1234321"); If anything, I feel like assert_eq!(format!("{:02x?}", b"Foo\0"), "[46, 6f, 6f, 00]"); (though once again I find myself frustrated that there is no |
Turns out it already does this. #[derive(Debug, Clone)]
struct Wrapper(f64);
fn main() {
println!("{:.7?}", vec![Wrapper(1.0); 4]);
}
|
Similar case from #55749.
|
@estebank that also already does something: It recursively sets the width, alignment and fill for integers and floats.
Debug formatting is not string formatting! |
I also get stuck with precision in debug formatting, I want it because sometimes print is tooo long and I want to just, for example, see what is top-level enum variant, Is there any way to set precision for whole debug output, something like |
So it sounds like width and precision are working as intended for |
As @fan-tom I, too, want to limit the length of a debug-printed output for some structure that can contain a lot of data inside while I only care about the first part of it. Sometimes derivative crate helps by allowing me to ignore a few fields. But sometimes it is not enough. For example, because there's only one field, and I want to see it, but still limit its length. Or it is an array. So currently I work around that (in tests) like this:
|
The
precision
field is ignored when formatting/printingDebug
representation. Apparently, it is honored when formattingDisplay
representation.https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=516b0c6222b4b351b69e45c15943821b
The text was updated successfully, but these errors were encountered: