Struct rkyv::rel_ptr::RelPtr

source ·
#[repr(C)]
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<E: Error>( from: usize, to: usize, out: *mut Self ) -> Result<(), E>

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

§Safety

out must point to a Self that is valid for reads and writes.

source

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

Creates a relative pointer from one position to another.

§Panics
  • If the offset between from and to does not fit in an isize
  • If the offset between from and to exceeds the offset storage
§Safety

out must point to a Self that is valid for reads and writes.

source§

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

source

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

Attempts to create a null relative pointer with default metadata.

§Safety

out must point to a Self that is valid for reads and writes.

source

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

Creates a null relative pointer with default metadata.

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

out must point to a Self that is valid for reads and writes.

source§

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

source

pub unsafe fn try_emplace_unsized<E: Error>( from: usize, to: usize, metadata: T::ArchivedMetadata, out: *mut Self ) -> Result<(), E>

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

§Safety

out must point to a Self that is valid for reads and writes.

source

pub unsafe fn emplace_unsized( from: usize, to: usize, metadata: T::ArchivedMetadata, out: *mut Self )

Creates a relative pointer from one position to another.

§Panics
  • If the offset between from and to does not fit in an isize
  • If the offset between from and to exceeds the offset storage
§Safety

out must point to a Self that is valid for reads and writes.

source

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

Gets the 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 unsafe fn as_ptr(&self) -> *mut T

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 fn as_ptr_wrapping(&self) -> *mut T

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.

Trait Implementations§

source§

impl<T: ArchivePointee + ?Sized, O, __C: Fallible + ?Sized> CheckBytes<__C> for RelPtr<T, O>
where <__C as Fallible>::Error: Trace, RawRelPtr<O>: CheckBytes<__C>, T::ArchivedMetadata: CheckBytes<__C>, PhantomData<T>: 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<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.
source§

impl<T, O> Portable for RelPtr<T, O>

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<T: ?Sized, O> Sync for RelPtr<T, O>
where O: Sync, T: 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> 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.