Skip to main content

RawRelPtr

Struct RawRelPtr 

Source
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>

Source

pub fn try_emplace_invalid<E: Source>(out: Place<Self>) -> Result<(), E>

Attempts to create an invalid RawRelPtr in-place.

Source

pub fn emplace_invalid(out: Place<Self>)

Creates an invalid RawRelPtr in-place.

§Panics
  • If an offset of 1 does not fit in an isize
  • If an offset of 1 exceeds the offset storage
Source

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.

Source

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 out and to does not fit in an isize
  • If the offset between out and to exceeds the offset storage
Source

pub fn base_raw(this: *mut Self) -> *mut u8

Gets the base pointer for the pointed-to relative pointer.

Source

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.

Source

pub unsafe fn as_ptr_raw(this: *mut Self) -> *mut ()

Calculates the memory address being pointed to by the pointed-to relative pointer.

§Safety
  • this must be non-null, properly-aligned, and point to a valid RawRelPtr.
  • The offset of this relative pointer, when added to its base, must be located in the same allocated object as it.
Source

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.

Source

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.

Source

pub fn base(&self) -> *const u8

Gets the base pointer for the relative pointer.

Source

pub fn base_mut(this: Seal<'_, Self>) -> *mut u8

Gets the mutable base pointer for the relative pointer.

Source

pub fn offset(&self) -> isize

Gets the offset of the relative pointer from its base.

Source

pub fn is_invalid(&self) -> bool

Gets whether the offset of the relative pointer is invalid.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl<O, __C: Fallible + ?Sized> CheckBytes<__C> for RawRelPtr<O>
where <__C as Fallible>::Error: Trace, O: CheckBytes<__C>, PhantomPinned: CheckBytes<__C>,

Source§

unsafe fn check_bytes( value: *const Self, context: &mut __C, ) -> Result<(), <__C as Fallible>::Error>

Checks whether the given pointer points to a valid value within the given context. Read more
Source§

impl<O: Debug> Debug for RawRelPtr<O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<O: Offset> Pointer for RawRelPtr<O>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> ArchivePointee for T

Source§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
Source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutRaw for T

Source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
Source§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

Source§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
Source§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.