Revert "util: Add ArcWrapped"
This reverts commit 5c1b28e4ed8b046a251609e5f7db4b4df9e710f5. It has only been needed to move Rust structure across C bridges. That's unneeded with more integration.
This commit is contained in:
35
src/util.rs
35
src/util.rs
@ -16,7 +16,6 @@ pub mod c {
|
|||||||
use std::os::raw::c_char;
|
use std::os::raw::c_char;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::str::Utf8Error;
|
use std::str::Utf8Error;
|
||||||
use std::sync::{ Arc, Mutex };
|
|
||||||
|
|
||||||
// traits
|
// traits
|
||||||
|
|
||||||
@ -130,40 +129,6 @@ pub mod c {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<T> COpaquePtr for Wrapped<T> {}
|
impl<T> COpaquePtr for Wrapped<T> {}
|
||||||
|
|
||||||
#[repr(transparent)]
|
|
||||||
pub struct ArcWrapped<T>(*const Mutex<T>);
|
|
||||||
|
|
||||||
impl<T> ArcWrapped<T> {
|
|
||||||
pub fn new(value: T) -> Self {
|
|
||||||
Self::wrap(Arc::new(Mutex::new(value)))
|
|
||||||
}
|
|
||||||
pub fn wrap(state: Arc<Mutex<T>>) -> Self {
|
|
||||||
Self(Arc::into_raw(state))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Extracts the reference to the data.
|
|
||||||
/// It may cause problems if attempted in more than one place
|
|
||||||
pub unsafe fn unwrap(self) -> Arc<Mutex<T>> {
|
|
||||||
Arc::from_raw(self.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a new reference to the same data.
|
|
||||||
/// Use for accessing the underlying data as a reference.
|
|
||||||
pub fn clone_ref(&self) -> Arc<Mutex<T>> {
|
|
||||||
// A bit dangerous: the Arc may be in use elsewhere
|
|
||||||
let used_rc = unsafe { Arc::from_raw(self.0) };
|
|
||||||
let rc = used_rc.clone();
|
|
||||||
Arc::into_raw(used_rc); // prevent dropping the original reference
|
|
||||||
rc
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> Clone for ArcWrapped<T> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
Self::wrap(self.clone_ref())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clones the underlying data structure, like ToOwned.
|
/// Clones the underlying data structure, like ToOwned.
|
||||||
|
|||||||
Reference in New Issue
Block a user