Struct Weak

Source
pub struct Weak<T: ?Sized, Owner: ?Sized = dyn Destruct + Send + Sync> { /* private fields */ }
Expand description

A projecting version of Weak which allows owning a containing struct but referencing a field.

Implementations§

Source§

impl<'a, T: 'a + Send + Sync> Weak<T, dyn Destruct + Send + Sync + 'a>

Source

pub fn new() -> Self

Constructs a new Weak<T> with erased owner.

Source§

impl<T, Owner> Weak<T, Owner>

Source

pub fn new_owner() -> Self

Constructs a new Weak<T, T> with typed owner.

Source§

impl<'a, T: ?Sized, Owner: 'a + Send + Sync> Weak<T, Owner>

Source

pub fn erase_owner(this: Self) -> Weak<T, dyn Destruct + Send + Sync + 'a>

Erases the owning type so that projected Weak<T> can be used uniformly.

Source§

impl<T: ?Sized, Owner: ?Sized> Weak<T, Owner>

Source

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

Returns a raw pointer to the object T pointed to by this Weak<T>.

The pointer is valid only if there are some strong references. The pointer may be dangling, unaligned, or even null otherwise.

Source

pub fn upgrade(&self) -> Option<Arc<T, Owner>>

Attempts to upgrade the Weak pointer to Arc<T>.

Returns None if no strong references exist.

Source

pub fn owner(this: &Self) -> Weak<Owner>

Gets a reference to the owning allocation.

Source

pub fn into_owner(this: Self) -> Weak<Owner>

Consumes this projected field, returning the owning allocation.

Source

pub fn project<U: Sized>( this: Self, projection: impl FnOnce(&T) -> &U, ) -> Weak<U, Owner>

Projects this allocation to a field.

If no strong references exist, the closure will not be called.

Source

pub fn ptr_eq(lhs: &Self, rhs: &Self) -> bool

Returns true if the two Weaks point to the same field in the same allocated object, or if both don’t point to anything (i.e. because they were created with Weak::new()).

See ptr::eq for the caveats when comparing dyn Trait pointers, which this does when the owner type is erased.

Source§

impl<T: ?Sized, Owner: ?Sized> Weak<T, Owner>

Source

pub fn unsize<U: ?Sized, F>( this: Self, with: Coercion<T, U, F>, ) -> Weak<U, Owner>
where T: Sized, F: FnOnce(*const T) -> *const U,

Available on crate feature unsize only.

Convert this pointer with an unsizing coercion (e.g. from T to dyn Trait or [T; N] to [T]).

Source

pub fn unsize_owner<Pwner: ?Sized, F>( this: Self, with: Coercion<Owner, Pwner, F>, ) -> Weak<T, Pwner>
where Owner: Sized, F: FnOnce(*const Owner) -> *const Pwner,

Available on crate feature unsize only.

Convert this pointer with an unsizing coercion of the owner (e.g. from T to dyn Trait or [T; N] to [T]).

Trait Implementations§

Source§

impl<T: ?Sized, Owner: ?Sized> Clone for Weak<T, Owner>

Source§

fn clone(&self) -> Self

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

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

Performs copy-assignment from source. Read more
Source§

impl<T, U: ?Sized, Owner: ?Sized> CoerciblePtr<U> for Weak<T, Owner>

Available on crate feature unsize only.
Source§

type Pointee = T

The type we point to. This influences which kinds of unsizing are possible.
Source§

type Output = Weak<U, Owner>

The output type when unsizing the pointee to U.
Source§

fn as_sized_ptr(&mut self) -> *mut Self::Pointee

Get the raw inner pointer.
Source§

unsafe fn replace_ptr(self, ptr: *mut U) -> Self::Output

Replace the container inner pointer with an unsized version. Read more
Source§

impl<T, Owner: ?Sized> Debug for Weak<T, Owner>
where T: Debug + ?Sized,

Source§

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

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

impl<T, Owner> Default for Weak<T, Owner>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T: 'a> Default for Weak<T, dyn Destruct + 'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T: 'a> Default for Weak<T, dyn Destruct + Send + 'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T: 'a> Default for Weak<T, dyn Destruct + Send + Sync + 'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> From<Weak<T>> for Weak<T, T>

Source§

fn from(owner: Weak<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: ?Sized, Owner: ?Sized> From<Weak<T, Owner>> for Weak<Owner>

Source§

fn from(this: Weak<T, Owner>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: ?Sized, Owner: 'a> From<Weak<T, Owner>> for Weak<T, dyn Destruct + 'a>

Source§

fn from(this: Weak<T, Owner>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: ?Sized, Owner: 'a + Send> From<Weak<T, Owner>> for Weak<T, dyn Destruct + Send + 'a>

Source§

fn from(this: Weak<T, Owner>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T: ?Sized, Owner: 'a + Send + Sync> From<Weak<T, Owner>> for Weak<T, dyn Destruct + Send + Sync + 'a>

Source§

fn from(this: Weak<T, Owner>) -> Self

Converts to this type from the input type.
Source§

impl<T: ?Sized, Owner: ?Sized> Send for Weak<T, Owner>
where for<'a> &'a T: Send, Weak<T>: Send,

Source§

impl<T: ?Sized, Owner: ?Sized> Sync for Weak<T, Owner>
where for<'a> &'a T: Sync, Weak<T>: Sync,

Source§

impl<T: ?Sized, Owner: ?Sized> UnwindSafe for Weak<T, Owner>
where for<'a> &'a T: UnwindSafe, Weak<Owner>: UnwindSafe,

Available on crate feature std only.

Auto Trait Implementations§

§

impl<T, Owner> Freeze for Weak<T, Owner>
where T: ?Sized, Owner: ?Sized,

§

impl<T, Owner> RefUnwindSafe for Weak<T, Owner>
where T: RefUnwindSafe + ?Sized, Owner: RefUnwindSafe + ?Sized,

§

impl<T, Owner> Unpin for Weak<T, Owner>
where T: ?Sized, Owner: ?Sized,

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, U> CoerceUnsize<U> for T
where T: CoerciblePtr<U>, U: ?Sized,

Source§

fn unsize<F>(self, with: Coercion<Self::Pointee, U, F>) -> Self::Output
where F: FnOnce(*const Self::Pointee) -> *const U,

Convert a pointer, as if with unsize coercion. 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.
Source§

impl<T> Destruct for T
where T: ?Sized,