use std::ffi::c_void;
use std::sync::Arc;
pub unsafe trait OpaqueContext {
fn into_raw(self) -> *mut c_void;
unsafe fn drop_raw(raw: *mut c_void);
}
unsafe impl<T: Sized + Send> OpaqueContext for Box<T> {
fn into_raw(self) -> *mut c_void {
Box::into_raw(self) as *mut _
}
unsafe fn drop_raw(raw: *mut c_void) {
if !raw.is_null() {
unsafe {
let _ = Box::from_raw(raw as *mut T);
}
}
}
}
unsafe impl<T: Sized + Send + Sync> OpaqueContext for Arc<T> {
fn into_raw(self) -> *mut c_void {
Arc::into_raw(self) as *mut c_void
}
unsafe fn drop_raw(raw: *mut c_void) {
if !raw.is_null() {
unsafe {
let _ = Arc::from_raw(raw as *const T);
}
}
}
}