diff --git a/embassy-hal-common/src/macros.rs b/embassy-hal-common/src/macros.rs index 51e4a5ee..ffa5e4fb 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(), )* } } } - }; } diff --git a/embassy/src/util/mod.rs b/embassy/src/util/mod.rs index 4d59147c..3ad760cd 100644 --- a/embassy/src/util/mod.rs +++ b/embassy/src/util/mod.rs @@ -2,10 +2,8 @@ mod forever; mod select; -mod steal; mod yield_now; pub use forever::*; pub use select::*; -pub use steal::*; pub use yield_now::*; diff --git a/embassy/src/util/steal.rs b/embassy/src/util/steal.rs deleted file mode 100644 index 07eb5fff..00000000 --- a/embassy/src/util/steal.rs +++ /dev/null @@ -1,13 +0,0 @@ -/// A type that can retrieved unsafely from anywhere. -pub trait Steal { - /// Retrieve and instance of this type. - /// - /// # Safety - /// - /// It is the responsibility of the application to ensure that the - /// usage of the returned instance is not in conflict with other uses - /// of this instance. - /// - /// The implementation may panic if the instance is already in use. - unsafe fn steal() -> Self; -}