#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Notification {
inner: metal_rust_ffi::Notification,
}
impl Notification {
#[must_use]
pub fn name(&self) -> &str {
self.inner.name()
}
#[must_use]
pub fn object_description(&self) -> Option<&str> {
self.inner.object_description()
}
#[must_use]
pub fn user_info_description(&self) -> Option<&str> {
self.inner.user_info_description()
}
}
pub struct Registration {
_inner: metal_rust_ffi::Registration,
}
pub struct NotificationCenter {
inner: metal_rust_ffi::NotificationCenter,
}
impl NotificationCenter {
#[must_use]
pub fn default_center() -> Self {
Self {
inner: metal_rust_ffi::NotificationCenter::default_center(),
}
}
#[must_use]
pub fn add_observer(
&self,
name: impl AsRef<str>,
handler: impl Fn(Notification) + Send + Sync + 'static,
) -> Registration {
let inner = self.inner.add_observer(name.as_ref(), move |inner| {
handler(Notification { inner });
});
Registration { _inner: inner }
}
pub fn post(&self, name: impl AsRef<str>) {
self.inner.post(name.as_ref());
}
}