Struct rkyv::rel_ptr::RelPtr

source ·
pub struct RelPtr<T: ArchivePointee + ?Sized, O> { /* private fields */ }
Expand description

A pointer which resolves to relative to its position in memory.

This is a strongly-typed version of RawRelPtr.

See Archive for an example of creating one.

Implementations§

source§

impl<T, O: Offset> RelPtr<T, O>

source

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

Attempts to create a relative pointer from one position to another.

Safety
  • from must be the position of out within the archive
  • to must be the position of some valid T
source

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

Creates a relative pointer from one position to another.

Panics
  • The offset between from and to does not fit in an isize
  • The offset between from and to exceeds the offset storage
Safety
  • from must be the position of out within the archive
  • to must be the position of some valid T
source§

impl<T: ArchivePointee + ?Sized, O: Offset> RelPtr<T, O>

source

pub unsafe fn try_emplace_null( pos: usize, out: *mut Self ) -> Result<(), OffsetError>

Attempts to create a null relative pointer with default metadata.

Safety

pos must be the position of out within the archive.

source

pub unsafe fn emplace_null(pos: usize, out: *mut Self)

Creates a null relative pointer with default metadata.

Panics
  • An offset of 0 does not fit in an isize
  • An offset of 0 exceeds the offset storage
Safety

pos must be the position of out within the archive.

source§

impl<T: ArchivePointee + ?Sized, O: Offset> RelPtr<T, O>

source

pub unsafe fn try_resolve_emplace<U: ArchiveUnsized<Archived = T> + ?Sized>( from: usize, to: usize, value: &U, metadata_resolver: U::MetadataResolver, out: *mut Self ) -> Result<(), OffsetError>

Attempts to create a relative pointer from one position to another.

Safety
  • from must be the position of out within the archive
  • to must be the position of some valid T
  • value must be the value being serialized
  • metadata_resolver must be the result of serializing the metadata of value
source

pub unsafe fn resolve_emplace<U: ArchiveUnsized<Archived = T> + ?Sized>( from: usize, to: usize, value: &U, metadata_resolver: U::MetadataResolver, out: *mut Self )

Creates a relative pointer from one position to another.

Panics
  • The offset between from and to does not fit in an isize
  • The offset between from and to exceeds the offset storage
Safety
  • from must be the position of out within the archive
  • to must be the position of some valid T
  • value must be the value being serialized
  • metadata_resolver must be the result of serializing the metadata of value
source

pub unsafe fn try_resolve_emplace_from_raw_parts( from: usize, to: usize, archived_metadata: <T as ArchivePointee>::ArchivedMetadata, out: *mut Self ) -> Result<(), OffsetError>

Attempts to create a relative pointer from one position to another given raw pointer metadata.

This does the same thing as RelPtr::try_resolve_emplace but you must supply the <T as ArchivePointee>::ArchivedMetadata yourself directly rather than through an implementation of ArchiveUnsized on some value.

Safety
  • from must be the position of out within the archive
  • to must be the position of some valid T
  • value must be the value being serialized
  • archived_metadata must produce valid metadata for the pointee of the resulting RelPtr (the thing being pointed at) when <T as ArchivePointee>::pointer_metadata(archived_metadata) is called.
source

pub unsafe fn resolve_emplace_from_raw_parts( from: usize, to: usize, archived_metadata: <T as ArchivePointee>::ArchivedMetadata, out: *mut Self )

Creates a relative pointer from one position to another given raw pointer metadata.

This does the same thing as RelPtr::resolve_emplace but you must supply the <T as ArchivePointee>::ArchivedMetadata yourself directly rather than through an implementation of ArchiveUnsized on some value.

Panics
  • The offset between from and to does not fit in an isize
  • The offset between from and to exceeds the offset storage
Safety
  • from must be the position of out within the archive
  • to must be the position of some valid T
  • value must be the value being serialized
  • archived_metadata must produce valid metadata for the pointee of the resulting RelPtr (the thing being pointed at) when <T as ArchivePointee>::pointer_metadata(archived_metadata) is called.
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 metadata(&self) -> &T::ArchivedMetadata

Gets the metadata of the relative pointer.

source

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

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

source

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

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

Trait Implementations§

source§

impl<T: ArchivePointee + ?Sized, O: Debug> Debug for RelPtr<T, O>

source§

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

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

impl<T: ArchivePointee + ?Sized, O: Offset> Pointer for RelPtr<T, O>

source§

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

Formats the value using the given formatter.

Auto Trait Implementations§

§

impl<T: ?Sized, O> RefUnwindSafe for RelPtr<T, O>

§

impl<T: ?Sized, O> Send for RelPtr<T, O>
where O: Send, T: Send, <T as ArchivePointee>::ArchivedMetadata: Send,

§

impl<T: ?Sized, O> Sync for RelPtr<T, O>
where O: Sync, T: Sync, <T as ArchivePointee>::ArchivedMetadata: Sync,

§

impl<T, O> !Unpin for RelPtr<T, O>

§

impl<T: ?Sized, O> UnwindSafe for RelPtr<T, O>

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