Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use derive-where instead of derivative #585

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/board/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

### Patch

- Use `derive-where` instead of `derivative`
- Update dependencies
- Remove workaround lint false positive

Expand Down
10 changes: 5 additions & 5 deletions crates/board/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/board/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
5 changes: 2 additions & 3 deletions crates/board/src/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B: crate::Api + ?Sized> {
/// The button that triggered the event.
pub button: Id<crate::Button<B>>,
Expand Down
47 changes: 5 additions & 42 deletions crates/board/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<B: Api + ?Sized> {
/// Button event.
#[cfg(feature = "api-button")]
Expand Down Expand Up @@ -186,11 +185,8 @@ pub enum Event<B: Api + ?Sized> {
///
/// 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<B: Api + ?Sized>(Void, PhantomData<B>);
#[derive_where(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Impossible<B: Api + ?Sized>(!, PhantomData<B>);

#[cfg(feature = "defmt")]
impl<B: Api + ?Sized> defmt::Format for Impossible<B> {
Expand All @@ -199,30 +195,13 @@ impl<B: Api + ?Sized> defmt::Format for Impossible<B> {
}
}

// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use Clone(bound = "") instead.
impl<B: Api + ?Sized> Clone for Impossible<B> {
fn clone(&self) -> Self {
*self
}
}

// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use PartialOrd(bound = "") instead.
impl<B: Api + ?Sized> PartialOrd for Impossible<B> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl<B: Api + ?Sized> Impossible<B> {
/// Provides a static proof of dead code.
pub fn unreachable(&self) -> ! {
match self.0 {}
}
}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
enum Void {}

/// Button interface.
#[cfg(feature = "api-button")]
pub type Button<B> = <B as Api>::Button;
Expand Down Expand Up @@ -271,9 +250,7 @@ pub type Uart<B> = <B as Api>::Uart;
pub type Usb<B> = <B as Api>::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<T: Support<usize> + ?Sized> {
// Invariant: value < T::SUPPORT
value: usize,
Expand All @@ -287,20 +264,6 @@ impl<T: Support<usize> + ?Sized> defmt::Format for Id<T> {
}
}

// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use Clone(bound = "") instead.
impl<T: Support<usize> + ?Sized> Clone for Id<T> {
fn clone(&self) -> Self {
*self
}
}

// TODO(https://github.com/mcarton/rust-derivative/issues/112): Use PartialOrd(bound = "") instead.
impl<T: Support<usize> + ?Sized> PartialOrd for Id<T> {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl<T: Support<usize>> Id<T> {
/// Creates a safe identifier for an API with countable support.
pub fn new(value: usize) -> Result<Self, Error> {
Expand Down
5 changes: 2 additions & 3 deletions crates/board/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B: crate::Api + ?Sized> {
/// The timer that triggered the event.
pub timer: Id<crate::Timer<B>>,
Expand Down
5 changes: 2 additions & 3 deletions crates/board/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<B: crate::Api + ?Sized> {
/// The UART that triggered the event.
pub uart: Id<crate::Uart<B>>,
Expand Down
31 changes: 10 additions & 21 deletions crates/cli-tools/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 10 additions & 21 deletions crates/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading