[−][src]Struct rel_ptr::RelPtr
This represents a relative pointers
A relative pointer stores an offset, and uses its that in combination with its current position in memory to point to a value
See crate documentation for more information
Safety
When using core::num::NonZero*, it is UB to have the RelPtr point to itself, this could be achieved
with
If you use RelPtr::from(offset), then you must ensure that the relative pointer is set with the
given functions to avoid UB
When using RelPtr with packed structs it is important to keep in mind that packed struct move fields
to align them to drop them. For example, the below example is UB
#[repr(packed)] struct Base(String, UnsafeThing); struct UnsafeThing(RelPtr<String>); // points into Base impl Drop for UnsafeThing { fn drop(&mut self) { // ... accessing `RelPtr<String>` here is UB } }
This is because when Base drops, all of the fields are moved to align them. So the offset between the String in
unsafe thing and the RelPtr<String> in UnsafeThing could be changed. This will result in UB if you try to access
String inside of UnsafeThing even if you enforce drop order!
Methods
impl<T: ?Sized + MetaData, I: Nullable> RelPtr<T, I>[src]
pub fn null() -> Self[src]
A null relative pointer has an offset of 0, (points to itself)
pub fn is_null(&self) -> bool[src]
Check if relative pointer is null
impl<T: ?Sized + MetaData, I: Delta> RelPtr<T, I>[src]
pub fn set(&mut self, value: &mut T) -> Result<(), I::Error>[src]
set the offset of a relative pointer,
if the offset cannot be calculated using the given
Delta, then Err will be returned, and there will be
no change to the offset
pub unsafe fn set_unchecked(&mut self, value: *mut T)[src]
set the offset of a relative pointer,
Safety
if the offset is out of bounds for the given Delta
then it's value is UB
if the given pointer is null, this is UB
pub unsafe fn as_raw_unchecked(&self) -> *mut T[src]
Converts the relative pointer into a normal raw pointer
Safety
You must ensure that the relative pointer was successfully set before
calling this function and that the value pointed to does not change it's
offset relative to RelPtr
if RelPtr::set was never called successfully, this function is UB
pub unsafe fn as_non_null_unchecked(&mut self) -> NonNull<T>[src]
pub unsafe fn as_ref_unchecked(&self) -> &T[src]
pub unsafe fn as_mut_unchecked(&mut self) -> &mut T[src]
impl<T: ?Sized + MetaData, I: Nullable> RelPtr<T, I>[src]
pub unsafe fn as_raw(&self) -> *mut T[src]
Converts the relative pointer into a normal raw pointer
Note: if self.is_null() then a null pointer will be returned
Safety
You must ensure that if the relative pointer was successfully set then
the value pointed to does not change it's offset relative to RelPtr
if the relative pointer was not successfully set RelPtr::as_raw returns null,
this function is safe for all types except for trait objects
because the only way to construct a RelPtr is to make a null ptr and change it
through RelPtr::set, but with trait objects it is impossible to create a v-table
so it will have an invalid v-table (which is UB)
pub unsafe fn as_non_null(&self) -> Option<NonNull<T>>[src]
pub unsafe fn as_ref(&self) -> Option<&T>[src]
Gets a reference from the relative pointer,
if the relative pointer is null, then None is
returned
Safety
Same as RelPtr::as_raw
pub unsafe fn as_mut(&mut self) -> Option<&mut T>[src]
Gets a mutable reference from the relative pointer,
if the relative pointer is null, then None is
returned
Safety
Same as RelPtr::as_raw
Trait Implementations
impl<T: ?Sized + MetaData, I: Delta> Clone for RelPtr<T, I>[src]
fn clone(&self) -> Self[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl<T: ?Sized + MetaData, I: Delta> PartialEq<RelPtr<T, I>> for RelPtr<T, I>[src]
fn eq(&self, other: &Self) -> bool[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool1.0.0[src]
This method tests for !=.
impl<T: ?Sized + MetaData, I: Delta> Eq for RelPtr<T, I>[src]
impl<T: ?Sized + MetaData, I: Delta> Copy for RelPtr<T, I>[src]
impl<T: ?Sized + MetaData, I: Delta> From<I> for RelPtr<T, I>[src]
impl<T: ?Sized + MetaData, I: Debug + Delta> Debug for RelPtr<T, I>[src]
impl<T: ?Sized + MetaData, I: Debug + Delta> Pointer for RelPtr<T, I>[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T[src]
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T> Borrow for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T, U> TryInto for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,