style: Introduce ArcSlice, a small wrapper over ThinArc but without an explicit header.

We could make the header PhantomData or something, but then we wouldn't be able
to bind to C++, since C++ doesn't have ZSTs. So add a canary instead to add a
runtime check of stuff being sane.

Differential Revision: https://phabricator.services.mozilla.com/D30133
This commit is contained in:
Emilio Cobos Álvarez 2019-05-09 10:53:50 +00:00
parent 2ed2151b3d
commit 0d5c4481b8
6 changed files with 98 additions and 3 deletions

View file

@ -784,6 +784,13 @@ pub struct ThinArc<H, T> {
phantom: PhantomData<(H, T)>,
}
impl<H: fmt::Debug, T: fmt::Debug> fmt::Debug for ThinArc<H, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self.deref(), f)
}
}
unsafe impl<H: Sync + Send, T: Sync + Send> Send for ThinArc<H, T> {}
unsafe impl<H: Sync + Send, T: Sync + Send> Sync for ThinArc<H, T> {}
@ -856,8 +863,12 @@ impl<H, T> ThinArc<H, T> {
}
/// Returns the address on the heap of the ThinArc itself -- not the T
/// within it -- for memory reporting.
///
/// within it -- for memory reporting, and bindings.
#[inline]
pub fn ptr(&self) -> *const c_void {
self.ptr.as_ptr() as *const ArcInner<T> as *const c_void
}
/// If this is a static ThinArc, this returns null.
#[inline]
pub fn heap_ptr(&self) -> *const c_void {
@ -866,7 +877,7 @@ impl<H, T> ThinArc<H, T> {
if is_static {
ptr::null()
} else {
self.ptr.as_ptr() as *const ArcInner<T> as *const c_void
self.ptr()
}
}
}