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

Implement Debug trait for serde_derive structs, enums, etc. #2761

Open
janis-ab opened this issue Jun 22, 2024 · 1 comment
Open

Implement Debug trait for serde_derive structs, enums, etc. #2761

janis-ab opened this issue Jun 22, 2024 · 1 comment

Comments

@janis-ab
Copy link

Writing derive macro code is hard and println!("{:?}", some_var) is very helpful when debugging and trying to understand things.

There are a lot of structs in serde_derive that do not implement Debug trait, i.e. enum TagType, struct RenameRule, etc. Yes, those are somewhat internal structs, but when implementing derive macro it is necessary to work with them.

I understand that for most use-cases Debug trait on those structs is not necessary or useful. It is useful only when developing derive macros, thus i would like to propose, in my opinion, a low maintenance, backwards compatible solution to this.

Create a feature flag debug-impls. It could be named anything, i just chose name similar to clone-impls in syn crate; since serde has that as dependency and naming convention would be somewhat similar.

Then in serde_derive code we could add cfg_attr lines like so:

#[derive(Copy, Clone)]
#[cfg_attr(feature = "debug-impls", derive(Debug))]
pub enum Identifier {
    No,
    Field,
    Variant,
}

or for structs that do not have anything derived:

#[cfg_attr(feature = "debug-impls", derive(Debug))]
pub enum Identifier {
    No,
    Field,
    Variant,
}

Syntax works in both cases.

I would like to take care of this and send PRs, if they are accepted.

@v3xro
Copy link

v3xro commented Jul 30, 2024

Would also be interested in seeing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants