Skip to content

Commit

Permalink
Improve debug str generator
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik authored and pvdrz committed Dec 1, 2024
1 parent 0c3ae5c commit d9576ea
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions bindgen-tests/tests/expectations/tests/derive-debug-bitfield.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions bindgen/codegen/impl_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,18 @@ impl<'a> ImplDebug<'a> for Item {
// Let's implement our own print function
Some((
format!("{name}: [{{}}]"),
vec![quote! {
self.#name_ident
.iter()
.enumerate()
.map(|(i, v)| format!("{}{:?}", if i > 0 { ", " } else { "" }, v))
.collect::<String>()
}],
vec![quote! {{
use std::fmt::Write as _;
let mut output = String::new();
let mut iter = self.#name_ident.iter();
if let Some(value) = iter.next() {
let _ = write!(output, "{value:?}");
for value in iter {
let _ = write!(output, ", {value:?}");
}
}
output
}}],
))
}
}
Expand Down

0 comments on commit d9576ea

Please sign in to comment.