Skip to content

Add a way to not implement the Debug trait #168

@locka99

Description

@locka99

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.

https://github.com/locka99/opcua/blob/master/types/src/status_codes.rs

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions