style: Make NotNull move its member pointer where possible.

Differential Revision: https://phabricator.services.mozilla.com/D72827
This commit is contained in:
Simon Giesecke 2020-05-05 09:09:01 +00:00 committed by Emilio Cobos Álvarez
parent 6a7c0b7e9c
commit 735fdedbe9

View file

@ -9,6 +9,7 @@ use std::marker::PhantomData;
use std::mem::{forget, transmute};
use std::ops::{Deref, DerefMut};
use std::ptr;
use gecko_bindings::structs::root::mozilla::detail::CopyablePtr;
/// Indicates that a given Servo type has a corresponding Gecko FFI type.
pub unsafe trait HasFFI: Sized + 'static {
@ -332,3 +333,16 @@ impl<GeckoType> OwnedOrNull<GeckoType> {
unsafe { transmute(self) }
}
}
impl<T> Deref for CopyablePtr<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.mPtr
}
}
impl<T> DerefMut for CopyablePtr<T> {
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
&mut self.mPtr
}
}