From a8eedd7feb1370e4b4540a26bd21d6a575ad00be Mon Sep 17 00:00:00 2001 From: Hosssein Assaran Date: Tue, 11 Mar 2025 15:45:05 +0330 Subject: [PATCH] Provide a better example which shows the usage of singleton! --- src/peripherals/singletons.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/peripherals/singletons.md b/src/peripherals/singletons.md index 1f3a556e..6d267ab8 100644 --- a/src/peripherals/singletons.md +++ b/src/peripherals/singletons.md @@ -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(); } ```