Skip to content

Commit

Permalink
Merge pull request #22 from steffahn/improve_debug_implementation
Browse files Browse the repository at this point in the history
Improve debug implementation
  • Loading branch information
Voultapher authored Oct 4, 2021
2 parents 5c05f54 + 7747236 commit ae22d0f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,14 +575,10 @@ macro_rules! _impl_automatic_derive {
fmt: &mut core::fmt::Formatter,
) -> core::result::Result<(), core::fmt::Error> {
self.with_dependent(|owner, dependent| {
write!(
fmt,
concat!(
stringify!($StructName),
" {{ owner: {:?}, dependent: {:?} }}"
),
owner, dependent
)
fmt.debug_struct(stringify!($StructName))
.field("owner", owner)
.field("dependent", dependent)
.finish()
})
}
}
Expand Down
23 changes: 23 additions & 0 deletions tests/self_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,29 @@ fn result_name_hygiene() {
);
}

#[test]
fn debug_impl() {
// See https://github.com/Voultapher/self_cell/pull/22
let ast_cell = PackedAstCell::new("xyz, abv".into(), |owner| owner.into());

assert_eq!(
format!("{:?}", &ast_cell),
"PackedAstCell { owner: \"xyz, abv\", dependent: Ast([\"z, \", \"yz\"]) }"
);

let hash_fmt = r#"PackedAstCell {
owner: "xyz, abv",
dependent: Ast(
[
"z, ",
"yz",
],
),
}"#;

assert_eq!(format!("{:#?}", ast_cell), hash_fmt);
}

#[test]
fn share_across_threads() {
// drop_joined takes &mut self, so that's not a thread concern anyway.
Expand Down

0 comments on commit ae22d0f

Please sign in to comment.