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<T: ?Sized, Owner: ?Sized> Weak<T, Owner>
impl<T: ?Sized, Owner: ?Sized> Weak<T, Owner>
Sourcepub fn as_ptr(&self) -> *const T
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.
Sourcepub fn upgrade(&self) -> Option<Arc<T, Owner>>
pub fn upgrade(&self) -> Option<Arc<T, Owner>>
Attempts to upgrade the Weak pointer to
Arc<T>.
Returns None if no strong references exist.
Sourcepub fn into_owner(this: Self) -> Weak<Owner>
pub fn into_owner(this: Self) -> Weak<Owner>
Consumes this projected field, returning the owning allocation.
Sourcepub fn project<U: Sized>(
this: Self,
projection: impl FnOnce(&T) -> &U,
) -> Weak<U, Owner>
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.
Sourcepub fn ptr_eq(lhs: &Self, rhs: &Self) -> bool
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>
impl<T: ?Sized, Owner: ?Sized> Weak<T, Owner>
Sourcepub fn unsize<U: ?Sized, F>(
this: Self,
with: Coercion<T, U, F>,
) -> Weak<U, Owner>
Available on crate feature unsize only.
pub fn unsize<U: ?Sized, F>( this: Self, with: Coercion<T, U, F>, ) -> Weak<U, Owner>
unsize only.Convert this pointer with an unsizing coercion
(e.g. from T to dyn Trait or [T; N] to [T]).
Sourcepub fn unsize_owner<Pwner: ?Sized, F>(
this: Self,
with: Coercion<Owner, Pwner, F>,
) -> Weak<T, Pwner>
Available on crate feature unsize only.
pub fn unsize_owner<Pwner: ?Sized, F>( this: Self, with: Coercion<Owner, Pwner, F>, ) -> Weak<T, Pwner>
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, U: ?Sized, Owner: ?Sized> CoerciblePtr<U> for Weak<T, Owner>
Available on crate feature unsize only.
impl<T, U: ?Sized, Owner: ?Sized> CoerciblePtr<U> for Weak<T, Owner>
unsize only.Source§fn as_sized_ptr(&mut self) -> *mut Self::Pointee
fn as_sized_ptr(&mut self) -> *mut Self::Pointee
Source§impl<'a, T: ?Sized, Owner: 'a + Send> From<Weak<T, Owner>> for Weak<T, dyn Destruct + Send + 'a>
impl<'a, T: ?Sized, Owner: 'a + Send> From<Weak<T, Owner>> for Weak<T, dyn Destruct + Send + 'a>
Source§impl<'a, T: ?Sized, Owner: 'a + Send + Sync> From<Weak<T, Owner>> for Weak<T, dyn Destruct + Send + Sync + 'a>
impl<'a, T: ?Sized, Owner: 'a + Send + Sync> From<Weak<T, Owner>> for Weak<T, dyn Destruct + Send + Sync + 'a>
impl<T: ?Sized, Owner: ?Sized> Send for Weak<T, Owner>
impl<T: ?Sized, Owner: ?Sized> Sync for Weak<T, Owner>
impl<T: ?Sized, Owner: ?Sized> UnwindSafe for Weak<T, Owner>
std only.