diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-07-22 16:06:45 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-07-22 16:32:19 +0200 |
| commit | ffbd9363f2a52fd27c81bbfbbe8e0e605a1ece86 (patch) | |
| tree | f894f84ddebbac50ad4eb853e4686d76b242d6e1 | |
| parent | a77ff721977e6071feb7000059d7e6185965949f (diff) | |
Change steal() from trait to inherent fns.
| -rw-r--r-- | embassy-hal-common/src/macros.rs | 24 | ||||
| -rw-r--r-- | embassy/src/util/mod.rs | 2 | ||||
| -rw-r--r-- | embassy/src/util/steal.rs | 13 |
3 files changed, 16 insertions, 23 deletions
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 { | |||
| 8 | pub struct $name { _private: () } | 8 | pub struct $name { _private: () } |
| 9 | 9 | ||
| 10 | $(#[$cfg])? | 10 | $(#[$cfg])? |
| 11 | impl embassy::util::Steal for $name { | 11 | impl $name { |
| 12 | /// Unsafely create an instance of this peripheral out of thin air. | ||
| 13 | /// | ||
| 14 | /// # Safety | ||
| 15 | /// | ||
| 16 | /// You must ensure that you're only using one instance of this type at a time. | ||
| 12 | #[inline] | 17 | #[inline] |
| 13 | unsafe fn steal() -> Self { | 18 | pub unsafe fn steal() -> Self { |
| 14 | Self{ _private: ()} | 19 | Self{ _private: ()} |
| 15 | } | 20 | } |
| 16 | } | 21 | } |
| @@ -23,7 +28,6 @@ macro_rules! peripherals { | |||
| 23 | self | 28 | self |
| 24 | } | 29 | } |
| 25 | } | 30 | } |
| 26 | |||
| 27 | )* | 31 | )* |
| 28 | } | 32 | } |
| 29 | 33 | ||
| @@ -48,23 +52,27 @@ macro_rules! peripherals { | |||
| 48 | panic!("init called more than once!") | 52 | panic!("init called more than once!") |
| 49 | } | 53 | } |
| 50 | _EMBASSY_DEVICE_PERIPHERALS = true; | 54 | _EMBASSY_DEVICE_PERIPHERALS = true; |
| 51 | <Self as embassy::util::Steal>::steal() | 55 | Self::steal() |
| 52 | }) | 56 | }) |
| 53 | } | 57 | } |
| 54 | } | 58 | } |
| 55 | 59 | ||
| 56 | impl embassy::util::Steal for Peripherals { | 60 | impl Peripherals { |
| 61 | /// Unsafely create an instance of this peripheral out of thin air. | ||
| 62 | /// | ||
| 63 | /// # Safety | ||
| 64 | /// | ||
| 65 | /// You must ensure that you're only using one instance of this type at a time. | ||
| 57 | #[inline] | 66 | #[inline] |
| 58 | unsafe fn steal() -> Self { | 67 | pub unsafe fn steal() -> Self { |
| 59 | Self { | 68 | Self { |
| 60 | $( | 69 | $( |
| 61 | $(#[$cfg])? | 70 | $(#[$cfg])? |
| 62 | $name: <peripherals::$name as embassy::util::Steal>::steal(), | 71 | $name: peripherals::$name::steal(), |
| 63 | )* | 72 | )* |
| 64 | } | 73 | } |
| 65 | } | 74 | } |
| 66 | } | 75 | } |
| 67 | |||
| 68 | }; | 76 | }; |
| 69 | } | 77 | } |
| 70 | 78 | ||
diff --git a/embassy/src/util/mod.rs b/embassy/src/util/mod.rs index 4d59147c1..3ad760cd4 100644 --- a/embassy/src/util/mod.rs +++ b/embassy/src/util/mod.rs | |||
| @@ -2,10 +2,8 @@ | |||
| 2 | 2 | ||
| 3 | mod forever; | 3 | mod forever; |
| 4 | mod select; | 4 | mod select; |
| 5 | mod steal; | ||
| 6 | mod yield_now; | 5 | mod yield_now; |
| 7 | 6 | ||
| 8 | pub use forever::*; | 7 | pub use forever::*; |
| 9 | pub use select::*; | 8 | pub use select::*; |
| 10 | pub use steal::*; | ||
| 11 | pub use yield_now::*; | 9 | pub use yield_now::*; |
diff --git a/embassy/src/util/steal.rs b/embassy/src/util/steal.rs deleted file mode 100644 index 07eb5fffd..000000000 --- a/embassy/src/util/steal.rs +++ /dev/null | |||
| @@ -1,13 +0,0 @@ | |||
| 1 | /// A type that can retrieved unsafely from anywhere. | ||
| 2 | pub trait Steal { | ||
| 3 | /// Retrieve and instance of this type. | ||
| 4 | /// | ||
| 5 | /// # Safety | ||
| 6 | /// | ||
| 7 | /// It is the responsibility of the application to ensure that the | ||
| 8 | /// usage of the returned instance is not in conflict with other uses | ||
| 9 | /// of this instance. | ||
| 10 | /// | ||
| 11 | /// The implementation may panic if the instance is already in use. | ||
| 12 | unsafe fn steal() -> Self; | ||
| 13 | } | ||
