pub trait RwLockEvent<T: ::eventbus::Event> {
fn metadata_lock() -> &'static ::std::sync::RwLock<::eventbus::EventMetadata<T>>;
}
macro_rules! rwlock_event {
($t:ty) => (
impl $crate::macros::event::RwLockEvent<$t> for $t {
fn metadata_lock() -> &'static ::std::sync::RwLock<$crate::eventbus::EventMetadata<$t>> {
lazy_static! {
static ref EVENT_METADATA: ::std::sync::RwLock<$crate::eventbus::EventMetadata<$t>> = ::std::sync::RwLock::new($crate::eventbus::EventMetadata::new());
}
&EVENT_METADATA
}
}
impl Event for $t {
fn event_metadata<F, R>(f: F) -> R where F: FnOnce(&$crate::eventbus::EventMetadata<Self>) -> R {
f(&<Self as $crate::macros::event::RwLockEvent<$t>>::metadata_lock().read().unwrap())
}
fn mut_metadata<F, R>(f: F) -> R where F: FnOnce(&mut $crate::eventbus::EventMetadata<Self>) -> R {
f(&mut <Self as $crate::macros::event::RwLockEvent<$t>>::metadata_lock().write().unwrap())
}
}
);
($t:ty, $f:ident) => (
impl $crate::macros::event::RwLockEvent<$t> for $t {
fn metadata_lock() -> &'static ::std::sync::RwLock<$crate::eventbus::EventMetadata<$t>> {
lazy_static! {
static ref EVENT_METADATA: ::std::sync::RwLock<$crate::eventbus::EventMetadata<$t>> = ::std::sync::RwLock::new($crate::eventbus::EventMetadata::new());
}
&EVENT_METADATA
}
}
impl Event for $t {
fn event_metadata<F, R>(f: F) -> R where F: FnOnce(&$crate::eventbus::EventMetadata<Self>) -> R {
f(&<Self as $crate::macros::event::RwLockEvent<$t>>::metadata_lock().read().unwrap())
}
fn mut_metadata<F, R>(f: F) -> R where F: FnOnce(&mut $crate::eventbus::EventMetadata<Self>) -> R {
f(&mut <Self as $crate::macros::event::RwLockEvent<$t>>::metadata_lock().write().unwrap())
}
fn cancellable() -> bool { true }
fn cancelled(&self) -> bool { self.$f }
fn cancel(&mut self, cancelled: bool) { self.$f = cancelled }
}
);
}