pub struct ThreadGroupKey { /* private fields */ }Expand description
A weak reference to a thread group that can be used in set and maps.
Implementations§
Methods from Deref<Target = Weak<ThreadGroup>>§
Sourcepub fn allocator(&self) -> &A
🔬This is a nightly-only experimental API. (allocator_api)
pub fn allocator(&self) -> &A
allocator_api)Returns a reference to the underlying allocator.
1.45.0 · 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.
§Examples
use std::sync::Arc;
use std::ptr;
let strong = Arc::new("hello".to_owned());
let weak = Arc::downgrade(&strong);
// Both point to the same object
assert!(ptr::eq(&*strong, weak.as_ptr()));
// The strong here keeps it alive, so we can still access the object.
assert_eq!("hello", unsafe { &*weak.as_ptr() });
drop(strong);
// But not any more. We can do weak.as_ptr(), but accessing the pointer would lead to
// undefined behavior.
// assert_eq!("hello", unsafe { &*weak.as_ptr() });1.4.0 · Sourcepub fn upgrade(&self) -> Option<Arc<T, A>>where
A: Clone,
pub fn upgrade(&self) -> Option<Arc<T, A>>where
A: Clone,
Attempts to upgrade the Weak pointer to an Arc, delaying
dropping of the inner value if successful.
Returns None if the inner value has since been dropped.
§Examples
use std::sync::Arc;
let five = Arc::new(5);
let weak_five = Arc::downgrade(&five);
let strong_five: Option<Arc<_>> = weak_five.upgrade();
assert!(strong_five.is_some());
// Destroy all strong pointers.
drop(strong_five);
drop(five);
assert!(weak_five.upgrade().is_none());1.41.0 · Sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
Gets the number of strong (Arc) pointers pointing to this allocation.
If self was created using Weak::new, this will return 0.
1.41.0 · Sourcepub fn weak_count(&self) -> usize
pub fn weak_count(&self) -> usize
Gets an approximation of the number of Weak pointers pointing to this
allocation.
If self was created using Weak::new, or if there are no remaining
strong pointers, this will return 0.
§Accuracy
Due to implementation details, the returned value can be off by 1 in
either direction when other threads are manipulating any Arcs or
Weaks pointing to the same allocation.
1.39.0 · Sourcepub fn ptr_eq(&self, other: &Weak<T, A>) -> bool
pub fn ptr_eq(&self, other: &Weak<T, A>) -> bool
Returns true if the two Weaks point to the same allocation similar to ptr::eq, or if
both don’t point to any allocation (because they were created with Weak::new()). However,
this function ignores the metadata of dyn Trait pointers.
§Notes
Since this compares pointers it means that Weak::new() will equal each
other, even though they don’t point to any allocation.
§Examples
use std::sync::Arc;
let first_rc = Arc::new(5);
let first = Arc::downgrade(&first_rc);
let second = Arc::downgrade(&first_rc);
assert!(first.ptr_eq(&second));
let third_rc = Arc::new(5);
let third = Arc::downgrade(&third_rc);
assert!(!first.ptr_eq(&third));Comparing Weak::new.
use std::sync::{Arc, Weak};
let first = Weak::new();
let second = Weak::new();
assert!(first.ptr_eq(&second));
let third_rc = Arc::new(());
let third = Arc::downgrade(&third_rc);
assert!(!first.ptr_eq(&third));Trait Implementations§
Source§impl Clone for ThreadGroupKey
impl Clone for ThreadGroupKey
Source§fn clone(&self) -> ThreadGroupKey
fn clone(&self) -> ThreadGroupKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ThreadGroupKey
impl Debug for ThreadGroupKey
Source§impl Deref for ThreadGroupKey
impl Deref for ThreadGroupKey
Source§impl From<&ThreadGroup> for ThreadGroupKey
impl From<&ThreadGroup> for ThreadGroupKey
Source§fn from(tg: &ThreadGroup) -> Self
fn from(tg: &ThreadGroup) -> Self
Source§impl<T: AsRef<ThreadGroup>> From<T> for ThreadGroupKey
impl<T: AsRef<ThreadGroup>> From<T> for ThreadGroupKey
Source§impl Hash for ThreadGroupKey
impl Hash for ThreadGroupKey
Source§impl Ord for ThreadGroupKey
impl Ord for ThreadGroupKey
Source§fn cmp(&self, other: &ThreadGroupKey) -> Ordering
fn cmp(&self, other: &ThreadGroupKey) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ThreadGroupKey
impl PartialEq for ThreadGroupKey
Source§impl PartialOrd for ThreadGroupKey
impl PartialOrd for ThreadGroupKey
impl Eq for ThreadGroupKey
impl StructuralPartialEq for ThreadGroupKey
Auto Trait Implementations§
impl Freeze for ThreadGroupKey
impl !RefUnwindSafe for ThreadGroupKey
impl Send for ThreadGroupKey
impl Sync for ThreadGroupKey
impl Unpin for ThreadGroupKey
impl !UnwindSafe for ThreadGroupKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> InstanceFromServiceTransport<T> for T
impl<T> InstanceFromServiceTransport<T> for T
§fn from_service_transport(handle: T) -> T
fn from_service_transport(handle: T) -> T
T to [Self]Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more