Skip to content

Commit a8eedd7

Browse files
Provide a better example which shows the usage of singleton!
1 parent 0b8219a commit a8eedd7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/peripherals/singletons.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,15 @@ use cortex_m::singleton;
6565
6666
fn main() {
6767
// OK if `main` is executed only once
68-
let x: &'static mut bool =
69-
singleton!(: bool = false).unwrap();
68+
let peripherals: &'static mut Peripherals =
69+
singleton!(: Peripherals = Peripherals {
70+
serial: Some(SerialPort),
71+
})
72+
.expect("Peripherals already taken!");
73+
74+
let serial_1 = peripherals.take_serial();
75+
// This panics!
76+
// let serial_2 = peripherals.take_serial();
7077
}
7178
```
7279

0 commit comments

Comments
 (0)