diff --git a/arcshift/CHANGELOG.md b/arcshift/CHANGELOG.md index b5a810f..3f096d0 100644 --- a/arcshift/CHANGELOG.md +++ b/arcshift/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.4.3 + +Fix Debug impl of ArcShift, so that it honors "{:#?}" format strings. + ## 0.4.2 Support rust 1.75 (0.4.1 regressed to require newer rust). diff --git a/arcshift/src/lib.rs b/arcshift/src/lib.rs index 755b379..37605fd 100644 --- a/arcshift/src/lib.rs +++ b/arcshift/src/lib.rs @@ -413,7 +413,9 @@ where T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { - write!(f, "ArcShift({:?})", self.shared_non_reloading_get()) + f.debug_tuple("ArcShift") + .field(&self.shared_non_reloading_get()) + .finish() } } diff --git a/arcshift/src/tests.rs b/arcshift/src/tests.rs index 287a85c..1362608 100644 --- a/arcshift/src/tests.rs +++ b/arcshift/src/tests.rs @@ -17,9 +17,9 @@ use std::hint::black_box; use std::mem::MaybeUninit; use std::string::ToString; use std::sync::atomic::AtomicUsize; -use std::thread; use std::time::Duration; use std::vec; +use std::{format, thread}; mod custom_fuzz; pub(crate) mod leak_detection; @@ -2656,6 +2656,26 @@ fn simple_threading_try_into_inner3() { }); } +#[test] +fn check_debug_impls() { + #[derive(Debug)] + struct Sample { + x: u32, + y: bool, + } + + let x = ArcShift::new(Sample { x: 42, y: false }); + let weak = ArcShift::downgrade(&x); + + assert_eq!(format!("{:?}", x), "ArcShift(Sample { x: 42, y: false })"); + assert_eq!(format!("{:?}", weak), "ArcShiftWeak(..)"); + assert_eq!( + format!("{:#?}", x), + "ArcShift(\n Sample {\n x: 42,\n y: false,\n },\n)" + ); + assert_eq!(format!("{:#?}", weak), "ArcShiftWeak(..)"); +} + /* This does not compile, nor should it compile. ArcShift must be invariant in 'a.