aboutsummaryrefslogtreecommitdiff
path: root/examples/generics.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2019-08-21 10:17:27 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-08-21 10:17:27 +0200
commit07b2b4d83078d0fd260d5f0812e8d5a34d02b793 (patch)
treedba2a8e8316e8cd868ccb7b46a80d63c5f61a224 /examples/generics.rs
parent0e146f8d1142672725b6abb38478f503a9261c80 (diff)
downloadrtic-07b2b4d83078d0fd260d5f0812e8d5a34d02b793.tar.gz
rtic-07b2b4d83078d0fd260d5f0812e8d5a34d02b793.tar.zst
rtic-07b2b4d83078d0fd260d5f0812e8d5a34d02b793.zip
doc up
Diffstat (limited to 'examples/generics.rs')
-rw-r--r--examples/generics.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/examples/generics.rs b/examples/generics.rs
index f0632d9a..eafc6308 100644
--- a/examples/generics.rs
+++ b/examples/generics.rs
@@ -29,6 +29,7 @@ const APP: () = {
hprintln!("UART0(STATE = {})", *STATE).unwrap();
+ // second argument has type `resources::shared`
advance(STATE, c.resources.shared);
rtfm::pend(Interrupt::UART1);
@@ -45,14 +46,16 @@ const APP: () = {
// just to show that `shared` can be accessed directly
*c.resources.shared += 0;
+ // second argument has type `Exclusive<u32>`
advance(STATE, Exclusive(c.resources.shared));
}
};
+// the second parameter is generic: it can be any type that implements the `Mutex` trait
fn advance(state: &mut u32, mut shared: impl Mutex<T = u32>) {
*state += 1;
- let (old, new) = shared.lock(|shared| {
+ let (old, new) = shared.lock(|shared: &mut u32| {
let old = *shared;
*shared += *state;
(old, *shared)