clack_common/events/spaces.rs
1//! Event spaces and associated utilities.
2
3mod core;
4mod id;
5
6pub use self::core::*;
7pub use id::*;
8
9use crate::events::UnknownEvent;
10use std::ffi::CStr;
11
12/// Holds all the possible event types included in a given event space.
13///
14/// # Safety
15///
16/// The implementers of this trait *must* ensure the [`NAME`](EventSpace::NAME) matches the name of
17/// the event space coming from the associated CLAP specification.
18pub unsafe trait EventSpace<'a>: Sized + 'a {
19 /// The specified name of this event space.
20 ///
21 /// This name *MUST* match the one defined by the CLAP specification for this event space.
22 const NAME: &'static CStr;
23
24 /// Casts the given unknown event to the matching event type.
25 ///
26 /// # Safety
27 ///
28 /// This method does not take the event space ID into consideration. It is up to the caller
29 /// to ensure that the given event does in fact belong to this event space.
30 unsafe fn from_unknown(event: &'a UnknownEvent) -> Option<Self>;
31
32 /// Returns this event as a type-erased [`UnknownEvent`].
33 fn as_unknown(&self) -> &'a UnknownEvent;
34}