use core::fmt;
use super::{Access, EventId};
#[derive(Debug, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Event {
pub id: EventId,
pub access: Access,
}
impl Event {
pub const fn new(id: EventId, access: Access) -> Self {
Self { id, access }
}
}
impl core::fmt::Display for Event {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.id)
}
}
#[allow(unused_macros)]
#[macro_export]
macro_rules! events {
($($event:expr $(,)?)*) => {
&[
$($event,)*
]
}
}
#[allow(unused_macros)]
#[macro_export]
macro_rules! event_enum {
($en:ty) => {
impl core::convert::TryFrom<$crate::dm::EventId> for $en {
type Error = $crate::error::Error;
fn try_from(id: $crate::dm::EventId) -> Result<Self, Self::Error> {
<$en>::from_repr(id).ok_or_else(|| $crate::error::ErrorCode::EventNotFound.into())
}
}
};
}