macro_rules! sc_retained {
($ty:ty, field = $field:ident, retain = $retain:path, release = $release:path $(,)?) => {
impl Clone for $ty {
fn clone(&self) -> Self {
Self {
$field: unsafe { $retain(self.$field) },
}
}
}
impl Drop for $ty {
fn drop(&mut self) {
if !self.$field.is_null() {
unsafe {
$release(self.$field);
}
}
}
}
};
($ty:ty, field = $field:ident, release = $release:path $(,)?) => {
impl Drop for $ty {
fn drop(&mut self) {
if !self.$field.is_null() {
unsafe {
$release(self.$field);
}
}
}
}
};
($ty:ty, retain = $retain:path, release = $release:path $(,)?) => {
impl Clone for $ty {
fn clone(&self) -> Self {
Self(unsafe { $retain(self.0) })
}
}
impl Drop for $ty {
fn drop(&mut self) {
if !self.0.is_null() {
unsafe {
$release(self.0);
}
}
}
}
};
($ty:ty, release = $release:path $(,)?) => {
impl Drop for $ty {
fn drop(&mut self) {
if !self.0.is_null() {
unsafe {
$release(self.0);
}
}
}
}
};
}
pub(crate) use sc_retained;