From 18ef8980d45d7b3daea5d8f1a3ed7508f3b6c7de Mon Sep 17 00:00:00 2001 From: Seb Kuzminsky Date: Wed, 23 Oct 2024 11:09:45 -0600 Subject: [PATCH] impl Debug for Signal, SignalReader, and SignalWriter This facilitates e.g. `my_task::spawn(my_signal_reader).unwrap();` --- rtic-sync/src/signal.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/rtic-sync/src/signal.rs b/rtic-sync/src/signal.rs index 4a30c57b7bc2..980f2a0d9bf1 100644 --- a/rtic-sync/src/signal.rs +++ b/rtic-sync/src/signal.rs @@ -17,6 +17,15 @@ pub struct Signal { store: UnsafeCell>, } +impl core::fmt::Debug for Signal +where + T: core::marker::Copy, +{ + fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + fmt.write_fmt(format_args!("Signal<{}>{{ .. }}", core::any::type_name::())) + } +} + impl Default for Signal { fn default() -> Self { Self::new() @@ -47,6 +56,15 @@ pub struct SignalWriter<'a, T: Copy> { parent: &'a Signal, } +impl core::fmt::Debug for SignalWriter<'_, T> +where + T: core::marker::Copy, +{ + fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + fmt.write_fmt(format_args!("SignalWriter<{}>{{ .. }}", core::any::type_name::())) + } +} + impl<'a, T: Copy> SignalWriter<'a, T> { /// Write a raw Store value to the Signal. fn write_inner(&mut self, value: Store) { @@ -74,6 +92,15 @@ pub struct SignalReader<'a, T: Copy> { parent: &'a Signal, } +impl core::fmt::Debug for SignalReader<'_, T> +where + T: core::marker::Copy, +{ + fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + fmt.write_fmt(format_args!("SignalReader<{}>{{ .. }}", core::any::type_name::())) + } +} + impl<'a, T: Copy> SignalReader<'a, T> { /// Immediately read and evict the latest value stored in the Signal. fn take(&mut self) -> Store {