pipewire/registry/
box_.rs1use std::{marker::PhantomData, ops::Deref, ptr};
5
6use crate::core::Core;
7
8use super::Registry;
9
10#[derive(Debug)]
11pub struct RegistryBox<'c> {
12 ptr: ptr::NonNull<pw_sys::pw_registry>,
13 core: PhantomData<&'c Core>,
14}
15
16impl<'c> RegistryBox<'c> {
17 pub unsafe fn from_raw(ptr: ptr::NonNull<pw_sys::pw_registry>) -> Self {
28 Self {
29 ptr,
30 core: PhantomData,
31 }
32 }
33}
34
35impl<'c> std::ops::Deref for RegistryBox<'c> {
36 type Target = Registry;
37
38 fn deref(&self) -> &Self::Target {
39 unsafe { self.ptr.cast::<Registry>().as_ref() }
40 }
41}
42
43impl<'c> AsRef<Registry> for RegistryBox<'c> {
44 fn as_ref(&self) -> &Registry {
45 self.deref()
46 }
47}
48
49impl<'c> Drop for RegistryBox<'c> {
50 fn drop(&mut self) {
51 unsafe {
52 pw_sys::pw_proxy_destroy(self.as_raw_ptr().cast());
53 }
54 }
55}