Skip to main content

RelativePtr

Struct RelativePtr 

Source
pub struct RelativePtr<T, const ALIGN: usize, E: Endian = NativeEndian> { /* private fields */ }
Available on (crate features alloc or std or derive or serde or zero-copy or static-size) and crate feature zero-copy only.
Expand description

A relative pointer that stores the offset from its own address to the target data. This allows zero-copy deserialization without runtime allocations.

Implementations§

Source§

impl<T, const ALIGN: usize, E: Endian> RelativePtr<T, ALIGN, E>

Source

pub fn new(offset: i32) -> Self

Creates a new RelativePtr with the given native offset.

Source

pub fn get<'a>(&self, buffer: &'a [u8]) -> Option<&'a T>
where T: ZeroCopy,

Resolves the pointer within the given buffer. Returns Some(&T) if the computed pointer is within the bounds of buffer and correctly aligned. Otherwise, returns None.

Trait Implementations§

Source§

impl<'a, T, const ALIGN: usize, E: Endian> Arbitrary<'a> for RelativePtr<T, ALIGN, E>

Available on crate feature fuzzing only.
Source§

fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'a>) -> Result<Self, Error>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl<'de, T: StaticSize, const ALIGN: usize, E: Endian, Context> BorrowDecode<'de, Context> for RelativePtr<T, ALIGN, E>

Source§

fn borrow_decode<D: BorrowDecoder<'de, Context = Context>>( decoder: &mut D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given [BorrowDecode]. Read more
Source§

impl<T: Clone, const ALIGN: usize, E: Clone + Endian> Clone for RelativePtr<T, ALIGN, E>

Source§

fn clone(&self) -> RelativePtr<T, ALIGN, E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, const ALIGN: usize, E: Debug + Endian> Debug for RelativePtr<T, ALIGN, E>

Source§

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

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

impl<T: StaticSize, const ALIGN: usize, E: Endian, Context> Decode<Context> for RelativePtr<T, ALIGN, E>

Source§

fn decode<D: Decoder<Context = Context>>( decoder: &mut D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given [Decode]. Read more
Source§

impl<T: ZeroCopy + DeepValidator, const ALIGN: usize, E: Endian> DeepValidator for RelativePtr<T, ALIGN, E>

Source§

fn is_valid_deep(&self, buffer: &[u8]) -> bool

Performs a deep validation check on the relative pointer.

Source§

impl<T: StaticSize, const ALIGN: usize, E: Endian> Encode for RelativePtr<T, ALIGN, E>

Source§

fn encode<EN: Encoder>(&self, encoder: &mut EN) -> Result<(), EncodeError>

Encode a given type. Read more
Source§

impl<T: PartialEq, const ALIGN: usize, E: PartialEq + Endian> PartialEq for RelativePtr<T, ALIGN, E>

Source§

fn eq(&self, other: &RelativePtr<T, ALIGN, E>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, const ALIGN: usize, E: Endian> StaticSize for RelativePtr<T, ALIGN, E>

Source§

const SIZE: usize

The size of the type in bytes.
Source§

impl<T: ZeroCopy, const ALIGN: usize, E: Endian> Validator for RelativePtr<T, ALIGN, E>

Source§

fn is_valid(&self, buffer: &[u8]) -> bool

Checks if the relative pointer is valid within the given buffer.

Source§

impl<T, const ALIGN: usize, E: Endian> ZeroCopy for RelativePtr<T, ALIGN, E>

Source§

const ALIGN: usize

The required alignment for this type.
Source§

impl<E: Endian, T, const ALIGN: usize> ZeroCopyType<E> for RelativePtr<T, ALIGN, E>
where T: ZeroCopy + ZeroCopyType<E>,

Available on crate feature alloc only.
Source§

type Builder = RelativeBuilder<<T as ZeroCopyType<E>>::Builder, ALIGN>

The builder type associated with this trait.

Source§

impl<T: Copy, const ALIGN: usize, E: Copy + Endian> Copy for RelativePtr<T, ALIGN, E>

Source§

impl<T: Eq, const ALIGN: usize, E: Eq + Endian> Eq for RelativePtr<T, ALIGN, E>

Source§

impl<T, const ALIGN: usize, E: Endian> StructuralPartialEq for RelativePtr<T, ALIGN, E>

Auto Trait Implementations§

§

impl<T, const ALIGN: usize, E> Freeze for RelativePtr<T, ALIGN, E>

§

impl<T, const ALIGN: usize, E> RefUnwindSafe for RelativePtr<T, ALIGN, E>

§

impl<T, const ALIGN: usize, E> Send for RelativePtr<T, ALIGN, E>
where T: Send, E: Send,

§

impl<T, const ALIGN: usize, E> Sync for RelativePtr<T, ALIGN, E>
where T: Sync, E: Sync,

§

impl<T, const ALIGN: usize, E> Unpin for RelativePtr<T, ALIGN, E>
where T: Unpin, E: Unpin,

§

impl<T, const ALIGN: usize, E> UnsafeUnpin for RelativePtr<T, ALIGN, E>

§

impl<T, const ALIGN: usize, E> UnwindSafe for RelativePtr<T, ALIGN, E>
where T: UnwindSafe, E: 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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.