{"id":21586131,"url":"https://github.com/magiclen/debug-helper","last_synced_at":"2025-04-10T20:20:35.748Z","repository":{"id":57617085,"uuid":"197862280","full_name":"magiclen/debug-helper","owner":"magiclen","description":"This crate provides declarative macros to help you implement the `Debug` trait manually.","archived":false,"fork":false,"pushed_at":"2023-09-11T06:01:44.000Z","size":53,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-03T04:47:47.048Z","etag":null,"topics":["debug","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magiclen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-07-20T01:11:03.000Z","updated_at":"2022-03-15T19:27:15.000Z","dependencies_parsed_at":"2022-08-29T05:31:46.487Z","dependency_job_id":"a459ff5c-0a44-4be1-b8e0-fb059455cc9b","html_url":"https://github.com/magiclen/debug-helper","commit_stats":{"total_commits":29,"total_committers":2,"mean_commits":14.5,"dds":0.03448275862068961,"last_synced_commit":"649d3a1c6db3db693708f056241f40d066464b12"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fdebug-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fdebug-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fdebug-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magiclen%2Fdebug-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magiclen","download_url":"https://codeload.github.com/magiclen/debug-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248289838,"owners_count":21078921,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debug","rust"],"created_at":"2024-11-24T15:12:45.479Z","updated_at":"2025-04-10T20:20:35.724Z","avatar_url":"https://github.com/magiclen.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Debug Helper\n====================\n\n[![CI](https://github.com/magiclen/debug-helper/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/debug-helper/actions/workflows/ci.yml)\n\nThis crate provides declarative macros to help you implement the `Debug` trait manually.\n\nInstead of this crate, in most cases, you can use the [`educe`](https://crates.io/crates/educe) crate to implement the `Debug` trait.\n\n## Examples\n\nFor structs,\n\n```rust\nuse std::fmt::{self, Formatter, Debug};\n\npub struct A {\n    pub f1: u8,\n    pub f2: i16,\n    pub f3: f64,\n}\n\nimpl Debug for A {\n    fn fmt(\u0026self, f: \u0026mut Formatter\u003c'_\u003e) -\u003e Result\u003c(), fmt::Error\u003e {\n        debug_helper::impl_debug_for_struct!(A, f, self, .f1, (.f3, \"{:.3}\", self.f3));\n    }\n}\n\nlet a = A {\n    f1: 1,\n    f2: 2,\n    f3: std::f64::consts::PI,\n};\n\nprintln!(\"{:#?}\", a);\n\n/*\n    A {\n        f1: 1,\n        f3: 3.142,\n    }\n*/\n```\n\nFor tuple structs,\n\n```rust\nuse std::fmt::{self, Formatter, Debug};\n\npub struct A(pub u8, pub i16, pub f64);\n\nimpl Debug for A {\n    fn fmt(\u0026self, f: \u0026mut Formatter\u003c'_\u003e) -\u003e Result\u003c(), fmt::Error\u003e {\n        debug_helper::impl_debug_for_tuple_struct!(A, f, self, .0, (.2, \"{:.3}\", self.2));\n    }\n}\n\nlet a = A(1, 2, std::f64::consts::PI);\n\nprintln!(\"{:#?}\", a);\n\n/*\n    A(\n        1,\n        3.142,\n    )\n*/\n```\n\nFor enums (without the enum name),\n\n```rust\nuse std::fmt::{self, Formatter, Debug};\n\npub enum A {\n    V1,\n    V2(u8, i16, f64),\n    V3 {\n        f1: u8,\n        f2: i16,\n        f3: f64,\n    },\n}\n\nimpl Debug for A {\n    fn fmt(\u0026self, f: \u0026mut Formatter\u003c'_\u003e) -\u003e Result\u003c(), fmt::Error\u003e {\n        debug_helper::impl_debug_for_enum!(A::{V1, (V2(f1, _, f3): (.f1, (.f3, \"{:.3}\", f3))), {V3{f1, f2: _, f3}: (.f1, (.f3, \"{:.3}\", f3))}}, f, self);\n    }\n}\n\nlet a = A::V1;\nlet b = A::V2(1, 2, std::f64::consts::PI);\nlet c = A::V3{\n    f1: 1,\n    f2: 2,\n    f3: std::f64::consts::PI,\n};\n\nprintln!(\"{:#?}\", a);\nprintln!(\"{:#?}\", b);\nprintln!(\"{:#?}\", c);\n\n/*\n    V1\n    V2(\n        1,\n        3.142,\n    )\n    V3 {\n        f1: 1,\n        f3: 3.142,\n    }\n*/\n```\n\nFor enums (with the enum name),\n\n```rust\nuse std::fmt::{self, Formatter, Debug};\n\npub enum A {\n    V1,\n    V2(u8, i16, f64),\n    V3 {\n        f1: u8,\n        f2: i16,\n        f3: f64,\n    },\n}\n\nimpl Debug for A {\n    fn fmt(\u0026self, f: \u0026mut Formatter\u003c'_\u003e) -\u003e Result\u003c(), fmt::Error\u003e {\n        debug_helper::impl_debug_for_enum!({A::V1, (V2(f1, _, f3): (.f1, (.f3, \"{:.3}\", f3))), {V3{f1, f2: _, f3}: (.f1, (.f3, \"{:.3}\", f3))}}, f, self);\n    }\n}\n\nlet a = A::V1;\nlet b = A::V2(1, 2, std::f64::consts::PI);\nlet c = A::V3{\n    f1: 1,\n    f2: 2,\n    f3: std::f64::consts::PI,\n};\n\nprintln!(\"{:#?}\", a);\nprintln!(\"{:#?}\", b);\nprintln!(\"{:#?}\", c);\n\n/*\n    A::V1\n    A::V2(\n        1,\n        3.142,\n    )\n    A::V3 {\n        f1: 1,\n        f3: 3.142,\n    }\n*/\n```\n\n\n\nGhost fields,\n\n```rust\nuse std::fmt::{self, Formatter, Debug};\n\npub struct A {\n    pub f1: u8,\n    pub f2: i16,\n    pub f3: f64,\n}\n\nimpl Debug for A {\n    fn fmt(\u0026self, f: \u0026mut Formatter\u003c'_\u003e) -\u003e Result\u003c(), fmt::Error\u003e {\n        debug_helper::impl_debug_for_struct!(A, f, self, .f1, (.f3, \"{:.3}\", self.f3), (.sum, \"{:.3}\", self.f1 as f64 + self.f2 as f64 + self.f3));\n    }\n}\n\nlet a = A {\n    f1: 1,\n    f2: 2,\n    f3: std::f64::consts::PI,\n};\n\nprintln!(\"{:#?}\", a);\n\n/*\n    A {\n        f1: 1,\n        f3: 3.142,\n        sum: 6.142,\n    }\n*/\n```\n\n```rust\nuse std::fmt::{self, Formatter, Debug};\n\npub struct A(pub u8, pub i16, pub f64);\n\nimpl Debug for A {\n    fn fmt(\u0026self, f: \u0026mut Formatter\u003c'_\u003e) -\u003e Result\u003c(), fmt::Error\u003e {\n        debug_helper::impl_debug_for_tuple_struct!(A, f, self, .0, (.2, \"{:.3}\", self.2), (.3, \"{:.3}\", self.0 as f64 + self.1 as f64 + self.2));\n    }\n}\n\nlet a = A(1, 2, std::f64::consts::PI);\n\nprintln!(\"{:#?}\", a);\n\n/*\n    A(\n        1,\n        3.142,\n        6.142,\n    )\n*/\n```\n\nFake structs,\n\n```rust\nuse std::fmt::{self, Formatter, Debug};\n\npub struct A(pub u8, pub i16, pub f64);\n\nimpl Debug for A {\n    fn fmt(\u0026self, f: \u0026mut Formatter\u003c'_\u003e) -\u003e Result\u003c(), fmt::Error\u003e {\n        debug_helper::impl_debug_for_struct!(A, f, self, let .f1 = self.0, let .f2 = self.1, let .f3 = self.2);\n    }\n}\n\nlet a = A(1, 2, std::f64::consts::PI);\n\nprintln!(\"{:#?}\", a);\n\n/*\n    A {\n        f1: 1,\n        f2: 2,\n        f3: 3.141592653589793,\n    }\n*/\n```\n\nFake tuple structs,\n\n```rust\nuse std::fmt::{self, Formatter, Debug};\n\npub struct A {\n    pub f1: u8,\n    pub f2: i16,\n    pub f3: f64,\n}\n\nimpl Debug for A {\n    fn fmt(\u0026self, f: \u0026mut Formatter\u003c'_\u003e) -\u003e Result\u003c(), fmt::Error\u003e {\n        debug_helper::impl_debug_for_tuple_struct!(A, f, self, let .0 = self.f1, let .1 = self.f2, let .2 = self.f3);\n    }\n}\n\nlet a = A {\n    f1: 1,\n    f2: 2,\n    f3: std::f64::consts::PI,\n};\n\nprintln!(\"{:#?}\", a);\n\n/*\n    A(\n        1,\n        2,\n        3.141592653589793,\n    )\n*/\n```\n\n## TODO\n\n1. Fake enum struct variants and tuple variants.\n1. Enum variants can be renamed.\n\n## Crates.io\n\nhttps://crates.io/crates/debug-helper\n\n## Documentation\n\nhttps://docs.rs/debug-helper\n\n## License\n\n[MIT](LICENSE)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagiclen%2Fdebug-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagiclen%2Fdebug-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagiclen%2Fdebug-helper/lists"}