Skip to content

Commit

Permalink
impl Debug for Signal, SignalReader, and SignalWriter
Browse files Browse the repository at this point in the history
This facilitates e.g. `my_task::spawn(my_signal_reader).unwrap();`
  • Loading branch information
SebKuzminsky committed Oct 23, 2024
1 parent f8eb018 commit 18ef898
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions rtic-sync/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ pub struct Signal<T: Copy> {
store: UnsafeCell<Store<T>>,
}

impl<T> core::fmt::Debug for Signal<T>
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::<T>()))
}
}

impl<T: Copy> Default for Signal<T> {
fn default() -> Self {
Self::new()
Expand Down Expand Up @@ -47,6 +56,15 @@ pub struct SignalWriter<'a, T: Copy> {
parent: &'a Signal<T>,
}

impl<T> 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::<T>()))
}
}

impl<'a, T: Copy> SignalWriter<'a, T> {
/// Write a raw Store value to the Signal.
fn write_inner(&mut self, value: Store<T>) {
Expand Down Expand Up @@ -74,6 +92,15 @@ pub struct SignalReader<'a, T: Copy> {
parent: &'a Signal<T>,
}

impl<T> 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::<T>()))
}
}

impl<'a, T: Copy> SignalReader<'a, T> {
/// Immediately read and evict the latest value stored in the Signal.
fn take(&mut self) -> Store<T> {
Expand Down

0 comments on commit 18ef898

Please sign in to comment.