X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Fc_types%2Fmod.rs;h=69319563b72a8c2fd284fda2de9f7a9de460731f;hp=274981da8e02a22c3a7dc24e7e61aba72ea9e5f5;hb=483aa2c8c37f626bb100c926bbad81a393332396;hpb=936e4d0f3a29469f3614ca1082fb94ff8f5e5dd2 diff --git a/lightning-c-bindings/src/c_types/mod.rs b/lightning-c-bindings/src/c_types/mod.rs index 274981d..6931956 100644 --- a/lightning-c-bindings/src/c_types/mod.rs +++ b/lightning-c-bindings/src/c_types/mod.rs @@ -607,3 +607,28 @@ pub(crate) mod ObjOps { } } } + +pub(crate) struct SmartPtr { + ptr: *mut T, +} +impl SmartPtr { + pub(crate) fn from_obj(o: T) -> Self { + Self { ptr: Box::into_raw(Box::new(o)) } + } + pub(crate) fn null() -> Self { + Self { ptr: std::ptr::null_mut() } + } +} +impl Drop for SmartPtr { + fn drop(&mut self) { + if self.ptr != std::ptr::null_mut() { + unsafe { Box::from_raw(self.ptr); } + } + } +} +impl std::ops::Deref for SmartPtr { + type Target = *mut T; + fn deref(&self) -> &*mut T { + &self.ptr + } +}