Skip to main content

RawFactoryPointer

Struct RawFactoryPointer 

Source
pub struct RawFactoryPointer<'a, T> { /* private fields */ }
Expand description

A low-level utility used to implement custom Factory pointer types.

This is a pointer type that allows read-only access to the pointed data, except that it does not deal with references or borrows. You cannot get a reference to the factory structure this points to, only get a copy of the factory structure.

This allows to more easily avoid violating Rust’s strict reference rules. Instead, this type only needs the pointer to adhere to the ptr::read function’s safety rules.

Implementations§

Source§

impl<'a, T> RawFactoryPointer<'a, T>

Source

pub fn new(inner: &'a T) -> RawFactoryPointer<'a, T>

Creates a new RawFactoryPointer from a shared reference to the factory data structure.

The lifetime of this new pointer is tied to the lifetime of the given reference.

Source

pub const unsafe fn from_raw(raw: NonNull<T>) -> RawFactoryPointer<'a, T>

Creates a new RawFactoryPointer from a non-null pointer to the factory data structure.

§Safety

Behavior is undefined if any of the following conditions are violated for the duration of the 'a lifetime:

  • raw must be valid for reads;
  • raw must be properly aligned (even if T has size 0);
  • raw must point to a properly initialized value of type T;
  • the memory raw points to must not be written to, it can only be read from.

These requirements are similar to those of the ptr::read function, except this function cannot cause UB if T is not Copy. This is because the only method on this type that actually performs a read, get, checks this statically via a Copy bound.

Source

pub const fn as_raw(&self) -> NonNull<T>

Returns a non-null pointer to the factory structure this pointer points to.

Source

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

Returns a raw pointer to the factory structure this pointer points to.

Source§

impl<T> RawFactoryPointer<'_, T>
where T: Copy,

Source

pub fn get(&self) -> T

Reads this pointer to return a copy of the factory structure.

This function is always safe to use.

Trait Implementations§

Source§

impl<'a, T> Clone for RawFactoryPointer<'a, T>
where T: Clone,

Source§

fn clone(&self) -> RawFactoryPointer<'a, T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'a, T> Copy for RawFactoryPointer<'a, T>
where T: Copy,

Source§

impl<T> Debug for RawFactoryPointer<'_, T>

Source§

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

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

impl<'a, T> Eq for RawFactoryPointer<'a, T>
where T: Eq,

Source§

impl<'a, T> Hash for RawFactoryPointer<'a, T>
where T: Hash,

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, T> PartialEq for RawFactoryPointer<'a, T>
where T: PartialEq,

Source§

fn eq(&self, other: &RawFactoryPointer<'a, T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T> Send for RawFactoryPointer<'_, T>
where T: Send,

Source§

impl<'a, T> StructuralPartialEq for RawFactoryPointer<'a, T>
where T: PartialEq,

Source§

impl<T> Sync for RawFactoryPointer<'_, T>
where T: Sync,

Auto Trait Implementations§

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

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

fn try_from(value: U) -> Result<T, !>

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.