diff --git a/util/src/sync/once.rs b/util/src/sync/once.rs index c5eca279..a9062cdd 100644 --- a/util/src/sync/once.rs +++ b/util/src/sync/once.rs @@ -205,12 +205,10 @@ impl InitOnce { impl fmt::Debug for InitOnce { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut d = f.debug_struct("InitOnce"); - d.field("type", &any::type_name::()); match self.state.load(Ordering::Acquire) { - INITIALIZED => d.field("value", self.get()).finish(), - INITIALIZING => d.field("value", &format_args!("")).finish(), - UNINITIALIZED => d.field("value", &format_args!("")).finish(), + INITIALIZED => self.get().fmt(f), + INITIALIZING => f.pad(""), + UNINITIALIZED => f.pad(""), _state => unsafe { unreachable_unchecked!("unexpected state value {}, this is a bug!", _state) }, @@ -358,13 +356,13 @@ where T: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut d = f.debug_struct("Lazy"); - d.field("type", &any::type_name::()) - .field("initializer", &format_args!("...")); match self.state.load(Ordering::Acquire) { - INITIALIZED => d.field("value", self.get_if_present().unwrap()).finish(), - INITIALIZING => d.field("value", &format_args!("")).finish(), - UNINITIALIZED => d.field("value", &format_args!("")).finish(), + INITIALIZED => self + .get_if_present() + .expect("if state is `INITIALIZED`, value should be present") + .fmt(f), + INITIALIZING => f.pad(""), + UNINITIALIZED => f.pad(""), _state => unsafe { unreachable_unchecked!("unexpected state value {}, this is a bug!", _state) },