diff options
author | 2019-08-21 10:17:27 +0200 | |
---|---|---|
committer | 2019-08-21 10:17:27 +0200 | |
commit | 07b2b4d83078d0fd260d5f0812e8d5a34d02b793 (patch) | |
tree | dba2a8e8316e8cd868ccb7b46a80d63c5f61a224 /examples/generics.rs | |
parent | 0e146f8d1142672725b6abb38478f503a9261c80 (diff) | |
download | rtic-07b2b4d83078d0fd260d5f0812e8d5a34d02b793.tar.gz rtic-07b2b4d83078d0fd260d5f0812e8d5a34d02b793.tar.zst rtic-07b2b4d83078d0fd260d5f0812e8d5a34d02b793.zip |
doc up
Diffstat (limited to 'examples/generics.rs')
-rw-r--r-- | examples/generics.rs | 5 |
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) |