diff options
Diffstat (limited to 'src/libcore/ptr.rs')
| -rw-r--r-- | src/libcore/ptr.rs | 89 |
1 files changed, 1 insertions, 88 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 23eb117680a..8c724b4d852 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -90,8 +90,7 @@ use mem; use clone::Clone; use intrinsics; -use kinds::{Copy, Send, Sync}; -use ops::Deref; +use kinds::{Send, Sync}; use option::Option; use option::Option::{Some, None}; @@ -111,32 +110,6 @@ pub use intrinsics::copy_memory; pub use intrinsics::set_memory; -/// A wrapper type for raw pointers and integers that will never be -/// NULL or 0 that might allow certain optimizations. -#[lang="non_zero"] -#[deriving(Clone, PartialEq, Eq, PartialOrd)] -#[experimental] -pub struct NonZero<T>(T); - -impl<T> NonZero<T> { - /// Create an instance of NonZero with the provided value. - /// You must indeed ensure that the value is actually "non-zero". - #[inline(always)] - pub unsafe fn new(inner: T) -> NonZero<T> { - NonZero(inner) - } -} - -impl<T> Deref<T> for NonZero<T> { - #[inline] - fn deref<'a>(&'a self) -> &'a T { - let NonZero(ref inner) = *self; - inner - } -} - -impl<T: Copy> Copy for NonZero<T> {} - /// Creates a null raw pointer. /// /// # Examples @@ -341,32 +314,6 @@ impl<T> RawPtr<T> for *const T { } } -impl<T> RawPtr<T> for NonZero<*const T> { - #[inline] - fn null() -> NonZero<*const T> { NonZero(null()) } - - #[inline] - fn is_null(&self) -> bool { false } - - #[inline] - fn to_uint(&self) -> uint { - let NonZero(p) = *self; - p as uint - } - - #[inline] - unsafe fn offset(self, count: int) -> NonZero<*const T> { - let NonZero(p) = self; - NonZero(intrinsics::offset(p, count)) - } - - #[inline] - unsafe fn as_ref<'a>(&self) -> Option<&'a T> { - let NonZero(p) = *self; - Some(&*p) - } -} - impl<T> RawPtr<T> for *mut T { #[inline] fn null() -> *mut T { null_mut() } @@ -392,32 +339,6 @@ impl<T> RawPtr<T> for *mut T { } } -impl<T> RawPtr<T> for NonZero<*mut T> { - #[inline] - fn null() -> NonZero<*mut T> { NonZero(null_mut()) } - - #[inline] - fn is_null(&self) -> bool { false } - - #[inline] - fn to_uint(&self) -> uint { - let NonZero(p) = *self; - p as uint - } - - #[inline] - unsafe fn offset(self, count: int) -> NonZero<*mut T> { - let NonZero(p) = self; - NonZero(intrinsics::offset(p as *const T, count) as *mut T) - } - - #[inline] - unsafe fn as_ref<'a>(&self) -> Option<&'a T> { - let NonZero(p) = *self; - Some(&*p) - } -} - impl<T> RawMutPtr<T> for *mut T { #[inline] unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> { @@ -429,14 +350,6 @@ impl<T> RawMutPtr<T> for *mut T { } } -impl<T> RawMutPtr<T> for NonZero<*mut T> { - #[inline] - unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> { - let NonZero(p) = *self; - Some(&mut *p) - } -} - // Equality for pointers impl<T> PartialEq for *const T { #[inline] |
