From ffbd9363f2a52fd27c81bbfbbe8e0e605a1ece86 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Fri, 22 Jul 2022 16:06:45 +0200 Subject: Change steal() from trait to inherent fns. --- embassy-hal-common/src/macros.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'embassy-hal-common/src') diff --git a/embassy-hal-common/src/macros.rs b/embassy-hal-common/src/macros.rs index 51e4a5eea..ffa5e4fb6 100644 --- a/embassy-hal-common/src/macros.rs +++ b/embassy-hal-common/src/macros.rs @@ -8,9 +8,14 @@ macro_rules! peripherals { pub struct $name { _private: () } $(#[$cfg])? - impl embassy::util::Steal for $name { + impl $name { + /// Unsafely create an instance of this peripheral out of thin air. + /// + /// # Safety + /// + /// You must ensure that you're only using one instance of this type at a time. #[inline] - unsafe fn steal() -> Self { + pub unsafe fn steal() -> Self { Self{ _private: ()} } } @@ -23,7 +28,6 @@ macro_rules! peripherals { self } } - )* } @@ -48,23 +52,27 @@ macro_rules! peripherals { panic!("init called more than once!") } _EMBASSY_DEVICE_PERIPHERALS = true; - ::steal() + Self::steal() }) } } - impl embassy::util::Steal for Peripherals { + impl Peripherals { + /// Unsafely create an instance of this peripheral out of thin air. + /// + /// # Safety + /// + /// You must ensure that you're only using one instance of this type at a time. #[inline] - unsafe fn steal() -> Self { + pub unsafe fn steal() -> Self { Self { $( $(#[$cfg])? - $name: ::steal(), + $name: peripherals::$name::steal(), )* } } } - }; } -- cgit