Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/peripherals/singletons.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,15 @@ use cortex_m::singleton;

fn main() {
// OK if `main` is executed only once
let x: &'static mut bool =
singleton!(: bool = false).unwrap();
let peripherals: &'static mut Peripherals =
singleton!(: Peripherals = Peripherals {
serial: Some(SerialPort),
})
.expect("Peripherals already taken!");

let serial_1 = peripherals.take_serial();
// This panics!
// let serial_2 = peripherals.take_serial();
}
```

Expand Down
Loading