servicepoint-binding-uniffi/src/macros.rs
2025-06-13 01:27:57 +02:00

47 lines
1.2 KiB
Rust

macro_rules! wrap_uniffi_object {
($orig_t:ident, $new_t:ident) => {
#[derive(uniffi::Object)]
pub struct $new_t {
pub(crate) actual: std::sync::RwLock<servicepoint::$orig_t>,
}
impl $new_t {
pub(crate) fn internal_new(actual: servicepoint::$orig_t) -> Arc<Self> {
Arc::new(Self {
actual: std::sync::RwLock::new(actual),
})
}
}
#[uniffi::export]
impl $new_t {
#[uniffi::constructor]
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
Self::internal_new(other.actual.read().unwrap().clone())
}
}
};
($t:ident) => {
wrap_uniffi_object!($t, $t);
};
}
pub(crate) use wrap_uniffi_object;
macro_rules! wrap_width_height {
($t:ident) => {
#[uniffi::export]
impl $t {
pub fn width(&self) -> u64 {
self.actual.read().unwrap().width() as u64
}
pub fn height(&self) -> u64 {
self.actual.read().unwrap().height() as u64
}
}
};
}
pub(crate) use wrap_width_height;