diff --git a/crates/board/CHANGELOG.md b/crates/board/CHANGELOG.md index 66d5a45c..1724e944 100644 --- a/crates/board/CHANGELOG.md +++ b/crates/board/CHANGELOG.md @@ -13,6 +13,7 @@ ### Patch +- Use `derive-where` instead of `derivative` - Update dependencies - Remove workaround lint false positive diff --git a/crates/board/Cargo.lock b/crates/board/Cargo.lock index 62bdcb57..a7886495 100644 --- a/crates/board/Cargo.lock +++ b/crates/board/Cargo.lock @@ -227,14 +227,14 @@ dependencies = [ ] [[package]] -name = "derivative" -version = "2.2.0" +name = "derive-where" +version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.66", ] [[package]] @@ -738,7 +738,7 @@ dependencies = [ "ccm", "crypto-common", "defmt", - "derivative", + "derive-where", "digest", "ecdsa", "elliptic-curve", diff --git a/crates/board/Cargo.toml b/crates/board/Cargo.toml index 75cb2275..e8d06412 100644 --- a/crates/board/Cargo.toml +++ b/crates/board/Cargo.toml @@ -22,7 +22,7 @@ bytemuck = { version = "1.16.0", default-features = false, optional = true } ccm = { version = "0.5.0", default-features = false, optional = true } crypto-common = { version = "0.1.6", default-features = false, optional = true } defmt = { version = "0.3.8", default-features = false, optional = true } -derivative = { version = "2.2.0", default-features = false, features = ["use_core"] } +derive-where = { version = "1.2.7", default-features = false, features = ["nightly"] } digest = { version = "0.10.7", default-features = false, optional = true } ecdsa = { version = "0.16.9", default-features = false, optional = true } elliptic-curve = { version = "0.13.8", default-features = false, optional = true } diff --git a/crates/board/src/button.rs b/crates/board/src/button.rs index 9e15d5f3..41cbf868 100644 --- a/crates/board/src/button.rs +++ b/crates/board/src/button.rs @@ -17,14 +17,13 @@ //! A button is an input interface with 2 states: pressed and released. Buttons must support //! triggering events when changing state. Events may be enabled or disabled per button. -use derivative::Derivative; +use derive_where::derive_where; use crate::{Error, Id, Support}; /// Button event. #[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[derive(Derivative)] -#[derivative(Debug(bound = ""), PartialEq(bound = ""), Eq(bound = ""))] +#[derive_where(Debug, PartialEq, Eq)] pub struct Event { /// The button that triggered the event. pub button: Id>, diff --git a/crates/board/src/lib.rs b/crates/board/src/lib.rs index 93900f53..fb1beca7 100644 --- a/crates/board/src/lib.rs +++ b/crates/board/src/lib.rs @@ -26,7 +26,7 @@ extern crate alloc; use core::marker::PhantomData; use core::ops::Deref; -use derivative::Derivative; +use derive_where::derive_where; use wasefire_error::Code; pub use wasefire_error::Error; @@ -151,8 +151,7 @@ pub trait Singleton: Sized { /// Events are de-duplicated if the previous one was not processed yet, because some events may /// trigger repeatedly. #[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[derive(Derivative)] -#[derivative(Debug(bound = ""), PartialEq(bound = ""), Eq(bound = ""))] +#[derive_where(Debug, PartialEq, Eq)] pub enum Event { /// Button event. #[cfg(feature = "api-button")] @@ -186,11 +185,8 @@ pub enum Event { /// /// This type is useful when the type parameter `B` needs to be mentioned in an enum. This type can /// be destructed by calling its unreachable method. -#[derive(Derivative)] -#[derivative(Debug(bound = ""), Copy(bound = ""), Hash(bound = ""))] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Ord(bound = ""))] -#[derivative(Ord = "feature_allow_slow_enum")] -pub struct Impossible(Void, PhantomData); +#[derive_where(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] +pub struct Impossible(!, PhantomData); #[cfg(feature = "defmt")] impl defmt::Format for Impossible { @@ -199,20 +195,6 @@ impl defmt::Format for Impossible { } } -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use Clone(bound = "") instead. -impl Clone for Impossible { - fn clone(&self) -> Self { - *self - } -} - -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use PartialOrd(bound = "") instead. -impl PartialOrd for Impossible { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - impl Impossible { /// Provides a static proof of dead code. pub fn unreachable(&self) -> ! { @@ -220,9 +202,6 @@ impl Impossible { } } -#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] -enum Void {} - /// Button interface. #[cfg(feature = "api-button")] pub type Button = ::Button; @@ -271,9 +250,7 @@ pub type Uart = ::Uart; pub type Usb = ::Usb; /// Valid identifier for a countable API. -#[derive(Derivative)] -#[derivative(Debug(bound = ""), Copy(bound = ""), Hash(bound = ""))] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Ord(bound = ""))] +#[derive_where(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Id + ?Sized> { // Invariant: value < T::SUPPORT value: usize, @@ -287,20 +264,6 @@ impl + ?Sized> defmt::Format for Id { } } -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use Clone(bound = "") instead. -impl + ?Sized> Clone for Id { - fn clone(&self) -> Self { - *self - } -} - -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use PartialOrd(bound = "") instead. -impl + ?Sized> PartialOrd for Id { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - impl> Id { /// Creates a safe identifier for an API with countable support. pub fn new(value: usize) -> Result { diff --git a/crates/board/src/timer.rs b/crates/board/src/timer.rs index d520666c..bfb97a0f 100644 --- a/crates/board/src/timer.rs +++ b/crates/board/src/timer.rs @@ -16,14 +16,13 @@ //! //! A timer triggers an event after a given amount of time (possibly periodically). -use derivative::Derivative; +use derive_where::derive_where; use crate::{Error, Id, Support}; /// Timer event. #[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[derive(Derivative)] -#[derivative(Debug(bound = ""), PartialEq(bound = ""), Eq(bound = ""))] +#[derive_where(Debug, PartialEq, Eq)] pub struct Event { /// The timer that triggered the event. pub timer: Id>, diff --git a/crates/board/src/uart.rs b/crates/board/src/uart.rs index cd612c37..c05a2d3b 100644 --- a/crates/board/src/uart.rs +++ b/crates/board/src/uart.rs @@ -14,14 +14,13 @@ //! UART interface. -use derivative::Derivative; +use derive_where::derive_where; use crate::{Error, Id, Support}; /// UART event. #[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[derive(Derivative)] -#[derivative(Debug(bound = ""), PartialEq(bound = ""), Eq(bound = ""))] +#[derive_where(Debug, PartialEq, Eq)] pub struct Event { /// The UART that triggered the event. pub uart: Id>, diff --git a/crates/scheduler/CHANGELOG.md b/crates/scheduler/CHANGELOG.md index ef9ac667..7c3d330f 100644 --- a/crates/scheduler/CHANGELOG.md +++ b/crates/scheduler/CHANGELOG.md @@ -4,6 +4,7 @@ ### Patch +- Use `derive-where` instead of `derivative` - Implement `defmt::Format` for `Key` when `defmt` is enabled - Stop using `log::Debug2Format()` when logging events - Make applet optional diff --git a/crates/scheduler/Cargo.lock b/crates/scheduler/Cargo.lock index 2ed9398b..94776ae8 100644 --- a/crates/scheduler/Cargo.lock +++ b/crates/scheduler/Cargo.lock @@ -227,14 +227,14 @@ dependencies = [ ] [[package]] -name = "derivative" -version = "2.2.0" +name = "derive-where" +version = "1.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +checksum = "62d671cc41a825ebabc75757b62d3d168c577f9149b2d49ece1dad1f72119d25" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.66", ] [[package]] @@ -753,7 +753,7 @@ dependencies = [ "ccm", "crypto-common", "defmt", - "derivative", + "derive-where", "digest", "ecdsa", "elliptic-curve", @@ -811,7 +811,7 @@ version = "0.3.2-git" dependencies = [ "bytemuck", "defmt", - "derivative", + "derive-where", "digest", "generic-array", "typenum", diff --git a/crates/scheduler/Cargo.toml b/crates/scheduler/Cargo.toml index 9c518981..7059c692 100644 --- a/crates/scheduler/Cargo.toml +++ b/crates/scheduler/Cargo.toml @@ -18,7 +18,7 @@ features = ["std", "wasm"] [dependencies] bytemuck = { version = "1.16.0", default-features = false } defmt = { version = "0.3.8", default-features = false, optional = true } -derivative = { version = "2.2.0", default-features = false, features = ["use_core"] } +derive-where = { version = "1.2.7", default-features = false, features = ["nightly"] } digest = { version = "0.10.7", default-features = false, features = ["mac"], optional = true } generic-array = { version = "=0.14.7", default-features = false, optional = true } typenum = { version = "1.17.0", default-features = false, optional = true } diff --git a/crates/scheduler/src/event.rs b/crates/scheduler/src/event.rs index 92305c54..6ecb5a1f 100644 --- a/crates/scheduler/src/event.rs +++ b/crates/scheduler/src/event.rs @@ -15,7 +15,7 @@ use alloc::vec; use core::borrow::Borrow; -use derivative::Derivative; +use derive_where::derive_where; use wasefire_board_api::{Api as Board, Event, Impossible}; #[cfg(feature = "wasm")] pub use wasefire_interpreter::InstId; @@ -42,10 +42,7 @@ pub struct InstId; // TODO: This could be encoded into a u32 for performance/footprint. #[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[derive(Derivative)] -#[derivative(Debug(bound = ""), Copy(bound = ""), Hash(bound = ""))] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Ord(bound = ""))] -#[derivative(Ord = "feature_allow_slow_enum")] +#[derive_where(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub enum Key { #[cfg(feature = "board-api-button")] Button(button::Key), @@ -62,20 +59,6 @@ pub enum Key { _Impossible(Impossible), } -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use Clone(bound = "") instead. -impl Clone for Key { - fn clone(&self) -> Self { - *self - } -} - -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use PartialOrd(bound = "") instead. -impl PartialOrd for Key { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - #[cfg_attr(not(feature = "board-api-button"), allow(unused_macros))] macro_rules! or_unreachable { ($feature:literal, [$($event:ident)*], $expr:expr) => {{ @@ -123,10 +106,7 @@ impl<'a, B: Board> From<&'a Event> for Key { } } -#[derive(Derivative)] -#[derivative(Debug(bound = ""), Clone(bound = ""))] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Ord(bound = ""))] -#[derivative(Ord = "feature_allow_slow_enum")] +#[derive_where(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] pub struct Handler { pub key: Key, pub inst: InstId, @@ -134,13 +114,6 @@ pub struct Handler { pub data: u32, } -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use PartialOrd(bound = "") instead. -impl PartialOrd for Handler { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - impl Borrow> for Handler { fn borrow(&self) -> &Key { &self.key diff --git a/crates/scheduler/src/event/button.rs b/crates/scheduler/src/event/button.rs index f7d3400c..3c13417a 100644 --- a/crates/scheduler/src/event/button.rs +++ b/crates/scheduler/src/event/button.rs @@ -14,32 +14,16 @@ use alloc::vec::Vec; -use derivative::Derivative; +use derive_where::derive_where; use wasefire_board_api::button::Event; use wasefire_board_api::{self as board, Api as Board, Id}; #[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[derive(Derivative)] -#[derivative(Debug(bound = ""), Copy(bound = ""), Hash(bound = ""))] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Ord(bound = ""))] +#[derive_where(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Key { pub button: Id>, } -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use Clone(bound = "") instead. -impl Clone for Key { - fn clone(&self) -> Self { - *self - } -} - -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use PartialOrd(bound = "") instead. -impl PartialOrd for Key { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - impl From> for crate::event::Key { fn from(key: Key) -> Self { crate::event::Key::Button(key) diff --git a/crates/scheduler/src/event/timer.rs b/crates/scheduler/src/event/timer.rs index 4c01f500..83dd5792 100644 --- a/crates/scheduler/src/event/timer.rs +++ b/crates/scheduler/src/event/timer.rs @@ -12,32 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -use derivative::Derivative; +use derive_where::derive_where; use wasefire_board_api::timer::Event; use wasefire_board_api::{self as board, Api as Board, Id}; #[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[derive(Derivative)] -#[derivative(Debug(bound = ""), Copy(bound = ""), Hash(bound = ""))] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Ord(bound = ""))] +#[derive_where(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Key { pub timer: Id>, } -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use Clone(bound = "") instead. -impl Clone for Key { - fn clone(&self) -> Self { - *self - } -} - -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use PartialOrd(bound = "") instead. -impl PartialOrd for Key { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - impl From> for crate::event::Key { fn from(key: Key) -> Self { crate::event::Key::Timer(key) diff --git a/crates/scheduler/src/event/uart.rs b/crates/scheduler/src/event/uart.rs index b2bba761..1002ddeb 100644 --- a/crates/scheduler/src/event/uart.rs +++ b/crates/scheduler/src/event/uart.rs @@ -12,33 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -use derivative::Derivative; +use derive_where::derive_where; use wasefire_board_api::uart::{Direction, Event}; use wasefire_board_api::{self as board, Api as Board, Id}; #[cfg_attr(feature = "defmt", derive(defmt::Format))] -#[derive(Derivative)] -#[derivative(Debug(bound = ""), Copy(bound = ""), Hash(bound = ""))] -#[derivative(PartialEq(bound = ""), Eq(bound = ""), Ord(bound = ""))] +#[derive_where(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Key { pub uart: Id>, pub direction: Direction, } -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use Clone(bound = "") instead. -impl Clone for Key { - fn clone(&self) -> Self { - *self - } -} - -// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use PartialOrd(bound = "") instead. -impl PartialOrd for Key { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - impl From> for crate::event::Key { fn from(key: Key) -> Self { crate::event::Key::Uart(key) diff --git a/crates/scheduler/src/lib.rs b/crates/scheduler/src/lib.rs index e0649780..2c195b19 100644 --- a/crates/scheduler/src/lib.rs +++ b/crates/scheduler/src/lib.rs @@ -26,7 +26,7 @@ use alloc::vec::Vec; use core::ffi::CStr; use core::marker::PhantomData; -use derivative::Derivative; +use derive_where::derive_where; use event::Key; use wasefire_applet_api::{self as api, Api, ArrayU32, Dispatch, Id, Signature, U32}; #[cfg(feature = "board-api-storage")] @@ -58,8 +58,7 @@ mod protocol; #[cfg(all(feature = "native", not(target_pointer_width = "32")))] compile_error!("Only 32-bits architectures support native applets."); -#[derive(Derivative)] -#[derivative(Default(bound = ""))] +#[derive_where(Default)] pub struct Events(VecDeque>); impl Events {