pub struct RawRelPtr<O> { /* private fields */ }Expand description
An untyped pointer which resolves relative to its position in memory.
This is the most fundamental building block in rkyv. It allows the construction and use of pointers that can be safely relocated as long as the source and target are moved together. This is what allows memory to be moved from disk into memory and accessed without decoding.
Regular pointers are absolute, meaning that the pointer can be moved without being invalidated. However, the pointee cannot be moved, otherwise the pointer is invalidated.
Relative pointers are relative, meaning that the pointer can be moved with the pointee without invalidating the pointer. However, if either the pointer or the pointee move independently, the pointer will be invalidated.
Implementations§
Source§impl<O: Offset> RawRelPtr<O>
impl<O: Offset> RawRelPtr<O>
Sourcepub fn try_emplace_invalid<E: Source>(out: Place<Self>) -> Result<(), E>
pub fn try_emplace_invalid<E: Source>(out: Place<Self>) -> Result<(), E>
Attempts to create an invalid RawRelPtr in-place.
Sourcepub fn emplace_invalid(out: Place<Self>)
pub fn emplace_invalid(out: Place<Self>)
Creates an invalid RawRelPtr in-place.
§Panics
- If an offset of
1does not fit in anisize - If an offset of
1exceeds the offset storage
Sourcepub fn try_emplace<E: Source>(to: usize, out: Place<Self>) -> Result<(), E>
pub fn try_emplace<E: Source>(to: usize, out: Place<Self>) -> Result<(), E>
Attempts to create a new RawRelPtr in-place between the given from
and to positions.
Sourcepub fn emplace(to: usize, out: Place<Self>)
pub fn emplace(to: usize, out: Place<Self>)
Creates a new RawRelPtr in-place between the given from and to
positions.
§Panics
- If the offset between
outandtodoes not fit in anisize - If the offset between
outandtoexceeds the offset storage
Sourcepub fn base_raw(this: *mut Self) -> *mut u8
pub fn base_raw(this: *mut Self) -> *mut u8
Gets the base pointer for the pointed-to relative pointer.
Sourcepub unsafe fn offset_raw(this: *mut Self) -> isize
pub unsafe fn offset_raw(this: *mut Self) -> isize
Gets the offset of the pointed-to relative pointer from its base.
§Safety
this must be non-null, properly-aligned, and point to a valid
RawRelPtr.
Sourcepub unsafe fn as_ptr_raw(this: *mut Self) -> *mut ()
pub unsafe fn as_ptr_raw(this: *mut Self) -> *mut ()
Calculates the memory address being pointed to by the pointed-to relative pointer.
§Safety
thismust be non-null, properly-aligned, and point to a validRawRelPtr.- The offset of this relative pointer, when added to its base, must be located in the same allocated object as it.
Sourcepub unsafe fn as_ptr_wrapping_raw(this: *mut Self) -> *mut ()
pub unsafe fn as_ptr_wrapping_raw(this: *mut Self) -> *mut ()
Calculates the memory address being pointed to by the pointed-to relative pointer using wrapping methods.
This method is a safer but potentially slower version of as_ptr_raw.
§Safety
this must be non-null, properly-aligned, and point to a valid
RawRelPtr.
Sourcepub unsafe fn is_invalid_raw(this: *mut Self) -> bool
pub unsafe fn is_invalid_raw(this: *mut Self) -> bool
Gets whether the offset of the pointed-to relative pointer is invalid.
§Safety
this must be non-null, properly-aligned, and point to a valid
RawRelPtr.
Sourcepub fn base_mut(this: Seal<'_, Self>) -> *mut u8
pub fn base_mut(this: Seal<'_, Self>) -> *mut u8
Gets the mutable base pointer for the relative pointer.
Sourcepub fn is_invalid(&self) -> bool
pub fn is_invalid(&self) -> bool
Gets whether the offset of the relative pointer is invalid.
Sourcepub unsafe fn as_ptr(&self) -> *const ()
pub unsafe fn as_ptr(&self) -> *const ()
Calculates the memory address being pointed to by this relative pointer.
§Safety
The offset of this relative pointer, when added to its base, must be located in the same allocated object as it.
Sourcepub unsafe fn as_mut_ptr(this: Seal<'_, Self>) -> *mut ()
pub unsafe fn as_mut_ptr(this: Seal<'_, Self>) -> *mut ()
Calculates the mutable memory address being pointed to by this relative pointer.
§Safety
The offset of this relative pointer, when added to its base, must be located in the same allocated object as it.
Sourcepub fn as_ptr_wrapping(&self) -> *const ()
pub fn as_ptr_wrapping(&self) -> *const ()
Calculates the memory address being pointed to by this relative pointer using wrapping methods.
This method is a safer but potentially slower version of as_ptr.
Sourcepub fn as_mut_ptr_wrapping(this: Seal<'_, Self>) -> *mut ()
pub fn as_mut_ptr_wrapping(this: Seal<'_, Self>) -> *mut ()
Calculates the mutable memory address being pointed to by this relative pointer using wrapping methods.
This method is a safer but potentially slower version of as_mut_ptr.
Trait Implementations§
impl<O> Portable for RawRelPtr<O>
Auto Trait Implementations§
impl<O> Freeze for RawRelPtr<O>where
O: Freeze,
impl<O> RefUnwindSafe for RawRelPtr<O>where
O: RefUnwindSafe,
impl<O> Send for RawRelPtr<O>where
O: Send,
impl<O> Sync for RawRelPtr<O>where
O: Sync,
impl<O> !Unpin for RawRelPtr<O>
impl<O> !UnsafeUnpin for RawRelPtr<O>
impl<O> UnwindSafe for RawRelPtr<O>where
O: UnwindSafe,
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.