Skip to main content

Shared

Struct Shared 

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

A pointer to a heap-allocated value protected by a guard.

This type represents a pointer that is guaranteed to remain valid for the lifetime of the guard. It cannot outlive the guard.

§Safety

The pointer is only valid while the guard is alive. Dereferencing the pointer after the guard is dropped is undefined behavior.

Implementations§

Source§

impl<'g, T> Shared<'g, T>

Source

pub unsafe fn from_raw(ptr: *mut T) -> Self

Creates a shared pointer from a raw pointer.

§Safety

The caller must ensure the pointer is valid and will remain valid for the lifetime of the guard.

Source

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

Returns the raw pointer.

Source

pub fn is_null(&self) -> bool

Returns true if the pointer is null.

Source

pub unsafe fn as_ref(&self) -> Option<&'g T>

Converts to an optional reference.

§Safety

The caller must ensure the pointer is properly aligned and points to a valid value of type T.

Source

pub unsafe fn deref(&self) -> &'g T

Converts to a reference without checking for null.

§Safety

The pointer must not be null and must point to a valid value.

Source

pub unsafe fn as_mut(&mut self) -> Option<&'g mut T>

Converts to a mutable reference.

§Safety

The caller must ensure exclusive access to the value.

Trait Implementations§

Source§

impl<'g, T> Clone for Shared<'g, T>

Source§

fn clone(&self) -> Self

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<'g, T> Debug for Shared<'g, T>

Source§

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

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

impl<'g, T> PartialEq for Shared<'g, T>

Source§

fn eq(&self, other: &Self) -> 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<'g, T> Copy for Shared<'g, T>

Source§

impl<'g, T> Eq for Shared<'g, T>

Auto Trait Implementations§

§

impl<'g, T> Freeze for Shared<'g, T>

§

impl<'g, T> RefUnwindSafe for Shared<'g, T>
where T: RefUnwindSafe,

§

impl<'g, T> !Send for Shared<'g, T>

§

impl<'g, T> !Sync for Shared<'g, T>

§

impl<'g, T> Unpin for Shared<'g, T>

§

impl<'g, T> UnwindSafe for Shared<'g, T>
where T: RefUnwindSafe,

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.