-
Notifications
You must be signed in to change notification settings - Fork 161
Description
I'm using bitflags!() on a large table of u32 status codes where the high 16-bits are a sequential number (1, 2, 3, 4 etc.) and the lower 16-bits are bit flags. Together these are OR'd together to make the code.
This all works fine except for the default Debug trait implementation which doesn't work properly with sequential values. This is easiest to demonstrate with a cut-down example:
#[macro_use]
extern crate bitflags;
bitflags! {
pub struct StatusCode: u32 {
const IS_ERROR = 0x8000_0000;
//...
const Good = 0;
//...
const BadEncodingError = 0x8006_0000;
const BadDecodingError = 0x8007_0000;
}
}
fn main() {
println!("{:?}", StatusCode::BadDecodingError);
}
This outputs IS_ERROR | BadEncodingError | BadDecodingError which is inappropriate in my case. I assume it is just doing a bitwise OR to all the values and appending them to the output string. I would like to be able to implement my own Debug trait and not generate the default one.
For example the bitflags!() macro could have a pattern or form which excludes emitting the Debug trait, ... pub struct (nodebug) StatusCode
Note I can override the fmt::Display trait for discrete cases where I need to print the StatusCode but it doesn't help when debug dumping out structs that have StatusCode as a member.