Struct rkyv::rel_ptr::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 pointee can be moved without invalidating the pointer. However, the target cannot be moved or the pointer is invalidated.

Relative pointers are relative, meaning that the pointee can be moved with the target without invalidating the pointer. However, if either the pointee or the target move independently, the pointer will be invalidated.

Implementations§

source§

impl<O: Offset> RawRelPtr<O>

source

pub unsafe fn manual_check_bytes<'a, C: Fallible + ?Sized>( value: *const Self, context: &mut C ) -> Result<&'a Self, Infallible>
where O: CheckBytes<C>,

Checks the bytes of the given raw relative pointer.

This is done rather than implementing CheckBytes to force users to manually write their CheckBytes implementation since they need to also provide the ownership model of their memory.

§Safety

The given pointer must be aligned and point to enough bytes to represent a RawRelPtr.

source§

impl<O: Offset> RawRelPtr<O>

source

pub unsafe fn try_emplace( from: usize, to: usize, out: *mut Self ) -> Result<(), OffsetError>

Attempts to create a new RawRelPtr in-place between the given from and to positions.

§Safety
  • out must be located at position from
  • to must be a position within the archive
source

pub unsafe fn emplace(from: usize, to: usize, out: *mut Self)

Creates a new RawRelPtr in-place between the given from and to positions.

§Safety
  • out must be located at position from
  • to must be a position within the archive
  • The offset between from and to must fit in an isize and not exceed the offset storage
source

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

Gets the base pointer for the relative pointer.

source

pub fn base_mut(&mut 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_null(&self) -> bool

Gets whether the offset of the relative pointer is 0.

source

pub fn as_ptr(&self) -> *const ()

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

source

pub fn as_mut_ptr(&mut self) -> *mut ()

Returns an unsafe mutable pointer to the memory address being pointed to by this relative pointer.

Trait Implementations§

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.

Auto Trait Implementations§

§

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

§

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<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
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>

Gets the layout of the type.
source§

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

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

§

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

§

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.