Struct cell_gc::ptr::Pointer
[−]
[src]
pub struct Pointer<T> { /* fields omitted */ }
A pointer to some T
in the GC heap.
Safety
A Pointer<T>
is a small step up in safety from a raw pointer. A valid
Pointer<T>
instance is a guarantee that:
The pointer points into the GC heap, within a GC-allocated page, and not on top of the
PageHeader
.The pointer has the alignment required by the type and GC.
Note that Pointer<T>
does not pin its referent like GcRef<T>
does. Therefore, a Pointer<T>
can still easily be made to dangle or point
at uninitialized memory! The Pointer<T>
type is not for general use (use
GcRef<T>
for that instead), only for GC internals. We have to make it
pub
so that #[derive(IntoHeap)]
can generate code that uses it, but no
one else should!
Methods
impl<T> Pointer<T>
[src]
unsafe fn new(ptr: *const T) -> Pointer<T>
Construct a new Pointer<T>
from a raw *const T
.
Safety
It is the responsibility of callers to ensure that the guarantees mentioned above hold true.
Panics
Panics if the pointer is not aligned properly, or if it would clobber
the GC's internal PageHeader
.
fn is_null(&self) -> bool
Is this pointer null?
unsafe fn as_ref(&self) -> &T
Get a reference to the pointed-to T
instance.
Safety
If a GC happens and reclaims the referent while the returned reference is in use, it will result in use-after-free.
If this pointer doesn't point at a valid T
instance, then all hell
will break loose.
Panics
Panics if the pointer is null.
fn as_raw(&self) -> *const T
Get the underlying raw pointer.
fn as_void(&self) -> *const ()
Get the underlying raw pointer as a *const ()
.
fn as_usize(&self) -> usize
Get the underlying raw pointer as a usize
.
Trait Implementations
impl<T: Hash> Hash for Pointer<T>
[src]
fn hash<__HT: Hasher>(&self, __arg_0: &mut __HT)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T: PartialOrd> PartialOrd for Pointer<T>
[src]
fn partial_cmp(&self, __arg_0: &Pointer<T>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, __arg_0: &Pointer<T>) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, __arg_0: &Pointer<T>) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, __arg_0: &Pointer<T>) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, __arg_0: &Pointer<T>) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<T: Ord> Ord for Pointer<T>
[src]
fn cmp(&self, __arg_0: &Pointer<T>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<T> Debug for Pointer<T>
[src]
impl<T> Clone for Pointer<T>
[src]
fn clone(&self) -> Pointer<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T> Copy for Pointer<T>
[src]
impl<T> PartialEq for Pointer<T>
[src]
fn eq(&self, other: &Pointer<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.