rstd 0.1.0
Loading...
Searching...
No Matches
alloc::sync::Weak< T > Class Template Referenceexport
module rstd.alloc

A non-owning, weakly-referenced companion to Arc that does not prevent deallocation. More...

Public Member Functions

void reset ()
 Releases the weak reference, decrementing the weak count.
 
auto upgrade () const noexcept -> Arc< T >
 Attempts to upgrade the Weak pointer to an Arc, succeeding only if strong references remain.
 
auto strong_count () const noexcept -> usize
 Returns the number of strong (Arc) pointers to the same allocation.
 
auto weak_count () const noexcept -> usize
 Returns the number of weak pointers to the same allocation (including this one).
 
bool expired () const noexcept
 Returns true if the value has been dropped (strong count is zero).
 
auto as_ptr () const noexcept
 Returns a raw pointer to the managed value.
 

Static Public Member Functions

static constexpr auto make () noexcept -> Weak
 Constructs a new empty Weak<T> without allocating any memory.
 

Friends

template<typename , typename >
struct rstd::Impl
 

Detailed Description

template<class T>
class alloc::sync::Weak< T >

A non-owning, weakly-referenced companion to Arc that does not prevent deallocation.

A thread-safe weak reference to an Arc-managed allocation.

Template Parameters
TThe type of the referenced value.

Member Function Documentation

◆ make()

template<class T >
static constexpr auto alloc::sync::Weak< T >::make ( ) -> Weak
inlinestaticconstexprnoexcept

Constructs a new empty Weak<T> without allocating any memory.

Calling upgrade on the return value always gives an empty Arc.

◆ strong_count()

template<class T >
auto alloc::sync::Weak< T >::strong_count ( ) const -> usize
inlinenoexcept

Returns the number of strong (Arc) pointers to the same allocation.

Returns
The current strong reference count.

◆ upgrade()

template<class T >
auto alloc::sync::Weak< T >::upgrade ( ) const -> Arc<T>
inlinenoexcept

Attempts to upgrade the Weak pointer to an Arc, succeeding only if strong references remain.

Returns
An Arc<T> if the value is still alive, or an empty Arc otherwise.

◆ weak_count()

template<class T >
auto alloc::sync::Weak< T >::weak_count ( ) const -> usize
inlinenoexcept

Returns the number of weak pointers to the same allocation (including this one).

Returns
The current weak reference count.

The documentation for this class was generated from the following file: