Skip to content

Commit 1e332f9

Browse files
committed
impl Deref for Observed
1 parent 46d43fe commit 1e332f9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

examples/comp_w_dac.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() -> ! {
6161
// * 0V at p1 => 0% duty
6262
// * VDDA at p1 => 100% duty
6363
loop {
64-
dac.as_mut().set_value(val);
64+
dac.set_value(val);
6565
match val {
6666
0 => dir = Direction::Upcounting,
6767
4095 => dir = Direction::Downcounting,

src/observable.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::Sealed;
2-
use core::marker::PhantomData;
2+
use core::{marker::PhantomData, ops};
33

44
pub trait ObservationLock: Sized + crate::Sealed {
55
type Peripheral: Observable;
@@ -65,3 +65,17 @@ impl<P: Observable, const N: usize> AsMut<P> for Observed<P, N> {
6565
&mut self.peripheral
6666
}
6767
}
68+
69+
impl<P: Observable, const N: usize> ops::Deref for Observed<P, N> {
70+
type Target = P;
71+
72+
fn deref(&self) -> &Self::Target {
73+
&self.peripheral
74+
}
75+
}
76+
77+
impl<P: Observable, const N: usize> ops::DerefMut for Observed<P, N> {
78+
fn deref_mut(&mut self) -> &mut Self::Target {
79+
&mut self.peripheral
80+
}
81+
}

0 commit comments

Comments
 (0)