Skip to content

Commit

Permalink
Signal ergo minor fixes (#986)
Browse files Browse the repository at this point in the history
* rtic_sync::signal: fix some docs typos

* impl Debug for Signal, SignalReader, and SignalWriter

This facilitates e.g. `my_task::spawn(my_signal_reader).unwrap();`
  • Loading branch information
SebKuzminsky authored Oct 23, 2024
1 parent 00baf53 commit 1461977
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions rtic-sync/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ 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 All @@ -41,12 +53,24 @@ impl<T: Copy> Signal<T> {
}
}

/// Fascilitates the writing of values to a Signal.
/// Facilitates the writing of values to a Signal.
#[derive(Clone)]
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 All @@ -69,11 +93,23 @@ impl<'a, T: Copy> SignalWriter<'a, T> {
}
}

/// Fascilitates the async reading of values from the Signal.
/// Facilitates the async reading of values from the Signal.
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 1461977

Please sign in to comment.