73 lines
1.9 KiB
Rust
73 lines
1.9 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;
|
|
|
|
macro_rules! wrap_get_set_fill_2d {
|
|
($t:ident, $contained:ident) => {
|
|
#[uniffi::export]
|
|
impl $t {
|
|
pub fn set(&self, x: u64, y: u64, value: $contained) {
|
|
self.actual
|
|
.write()
|
|
.unwrap()
|
|
.set(x as usize, y as usize, value)
|
|
}
|
|
|
|
pub fn get(&self, x: u64, y: u64) -> $contained {
|
|
self.actual.read().unwrap().get(x as usize, y as usize)
|
|
}
|
|
|
|
pub fn fill(&self, value: $contained) {
|
|
self.actual.write().unwrap().fill(value)
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
pub(crate) use wrap_get_set_fill_2d;
|