mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-23 12:12:50 +01:00
Signal ergo minor fixes (#986)
* 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();`
This commit is contained in:
parent
00baf53180
commit
1461977cf7
1 changed files with 38 additions and 2 deletions
|
@ -17,6 +17,18 @@ pub struct Signal<T: Copy> {
|
||||||
store: UnsafeCell<Store<T>>,
|
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> {
|
impl<T: Copy> Default for Signal<T> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self::new()
|
Self::new()
|
||||||
|
@ -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)]
|
#[derive(Clone)]
|
||||||
pub struct SignalWriter<'a, T: Copy> {
|
pub struct SignalWriter<'a, T: Copy> {
|
||||||
parent: &'a Signal<T>,
|
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> {
|
impl<'a, T: Copy> SignalWriter<'a, T> {
|
||||||
/// Write a raw Store value to the Signal.
|
/// Write a raw Store value to the Signal.
|
||||||
fn write_inner(&mut self, value: Store<T>) {
|
fn write_inner(&mut self, value: Store<T>) {
|
||||||
|
@ -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> {
|
pub struct SignalReader<'a, T: Copy> {
|
||||||
parent: &'a Signal<T>,
|
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> {
|
impl<'a, T: Copy> SignalReader<'a, T> {
|
||||||
/// Immediately read and evict the latest value stored in the Signal.
|
/// Immediately read and evict the latest value stored in the Signal.
|
||||||
fn take(&mut self) -> Store<T> {
|
fn take(&mut self) -> Store<T> {
|
||||||
|
|
Loading…
Reference in a new issue