Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signal ergo minor fixes #986

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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