use std::any::TypeId; use std::fmt::Debug; use std::hash::Hash; use seq_macro::seq; pub trait Event: Debug + 'static {} /// The ID of a [`Event`]. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Id { inner: TypeId, } impl Id { /// Returns the id of a [`Event`]; #[must_use] pub fn of() -> Self { Self { inner: TypeId::of::() } } } pub trait Ids { type Iter<'a>: Iterator where Self: 'a; fn iter(&self) -> Self::Iter<'_>; } /// A sequence of events. pub trait Sequence { type Ids: Ids; fn ids() -> Self::Ids; } macro_rules! impl_sequence { ($c: tt) => { seq!(I in 0..=$c { impl Ids for [Id; $c + 1] { type Iter<'a> = std::slice::Iter<'a, Id>; fn iter(&self) -> Self::Iter<'_> { self.into_iter() } } impl<#(Event~I: Event,)*> Sequence for (#(Event~I,)*) { type Ids = [Id; $c + 1]; fn ids() -> Self::Ids { [#( Id::of::(), )*] } } }); }; } seq!(C in 0..=64 { impl_sequence!(C); });