@@ -165,18 +165,29 @@ unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {}
165
165
#[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
166
166
impl < T : ?Sized + Unsize < U > , U : ?Sized > CoerceUnsized < Arc < U > > for Arc < T > { }
167
167
168
- /// A weak version of [`Arc`][arc].
168
+ /// `Weak` is a version of [`Arc`] that holds a non-owning reference to the
169
+ /// managed value. The value is accessed by calling [`upgrade`] on the `Weak`
170
+ /// pointer, which returns an [`Option`]`<`[`Arc`]`<T>>`.
169
171
///
170
- /// `Weak` pointers do not count towards determining if the inner value
171
- /// should be dropped.
172
+ /// Since a `Weak` reference does not count towards ownership, it will not
173
+ /// prevent the inner value from being dropped, and `Weak` itself makes no
174
+ /// guarantees about the value still being present and may return [`None`]
175
+ /// when [`upgrade`]d.
172
176
///
173
- /// The typical way to obtain a `Weak` pointer is to call
174
- /// [`Arc::downgrade`][downgrade].
177
+ /// A `Weak` pointer is useful for keeping a temporary reference to the value
178
+ /// within [`Arc`] without extending its lifetime. It is also used to prevent
179
+ /// circular references between [`Arc`] pointers, since mutual owning references
180
+ /// would never allow either [`Arc`] to be dropped. For example, a tree could
181
+ /// have strong [`Arc`] pointers from parent nodes to children, and `Weak`
182
+ /// pointers from children back to their parents.
175
183
///
176
- /// See the [`Arc`][arc] documentation for more details .
184
+ /// The typical way to obtain a `Weak` pointer is to call [`Arc::downgrade`] .
177
185
///
178
- /// [arc]: struct.Arc.html
179
- /// [downgrade]: struct.Arc.html#method.downgrade
186
+ /// [`Arc`]: struct.Arc.html
187
+ /// [`Arc::downgrade`]: struct.Arc.html#method.downgrade
188
+ /// [`upgrade`]: struct.Weak.html#method.upgrade
189
+ /// [`Option`]: ../../std/option/enum.Option.html
190
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
180
191
#[ stable( feature = "arc_weak" , since = "1.4.0" ) ]
181
192
pub struct Weak < T : ?Sized > {
182
193
ptr : Shared < ArcInner < T > > ,
@@ -766,14 +777,11 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
766
777
}
767
778
768
779
impl < T > Weak < T > {
769
- /// Constructs a new `Weak<T>`, without an accompanying instance of `T`.
770
- ///
771
- /// This allocates memory for `T`, but does not initialize it. Calling
772
- /// [`upgrade`][upgrade] on the return value always gives
773
- /// [`None`][option].
780
+ /// Constructs a new `Weak<T>`, allocating memory for `T` without initializing
781
+ /// it. Calling [`upgrade`] on the return value always gives [`None`].
774
782
///
775
- /// [upgrade]: struct.Weak.html#method.upgrade
776
- /// [option ]: ../../std/option/enum.Option.html
783
+ /// [` upgrade` ]: struct.Weak.html#method.upgrade
784
+ /// [`None` ]: ../../std/option/enum.Option.html#variant.None
777
785
///
778
786
/// # Examples
779
787
///
@@ -798,13 +806,13 @@ impl<T> Weak<T> {
798
806
}
799
807
800
808
impl < T : ?Sized > Weak < T > {
801
- /// Upgrades the `Weak` pointer to an [`Arc`][arc], if possible.
809
+ /// Attempts to upgrade the `Weak` pointer to an [`Arc`], extending
810
+ /// the lifetime of the value if successful.
802
811
///
803
- /// Returns [`None`][option] if the strong count has reached zero and the
804
- /// inner value was destroyed.
812
+ /// Returns [`None`] if the value has since been dropped.
805
813
///
806
- /// [arc ]: struct.Arc.html
807
- /// [option ]: ../../std/option/enum.Option.html
814
+ /// [`Arc` ]: struct.Arc.html
815
+ /// [`None` ]: ../../std/option/enum.Option.html#variant.None
808
816
///
809
817
/// # Examples
810
818
///
@@ -865,10 +873,7 @@ impl<T: ?Sized> Weak<T> {
865
873
866
874
#[ stable( feature = "arc_weak" , since = "1.4.0" ) ]
867
875
impl < T : ?Sized > Clone for Weak < T > {
868
- /// Makes a clone of the `Weak` pointer.
869
- ///
870
- /// This creates another pointer to the same inner value, increasing the
871
- /// weak reference count.
876
+ /// Makes a clone of the `Weak` pointer that points to the same value.
872
877
///
873
878
/// # Examples
874
879
///
@@ -900,14 +905,11 @@ impl<T: ?Sized> Clone for Weak<T> {
900
905
901
906
#[ stable( feature = "downgraded_weak" , since = "1.10.0" ) ]
902
907
impl < T > Default for Weak < T > {
903
- /// Constructs a new `Weak<T>`, without an accompanying instance of `T`.
908
+ /// Constructs a new `Weak<T>`, allocating memory for `T` without initializing
909
+ /// it. Calling [`upgrade`] on the return value always gives [`None`].
904
910
///
905
- /// This allocates memory for `T`, but does not initialize it. Calling
906
- /// [`upgrade`][upgrade] on the return value always gives
907
- /// [`None`][option].
908
- ///
909
- /// [upgrade]: struct.Weak.html#method.upgrade
910
- /// [option]: ../../std/option/enum.Option.html
911
+ /// [`upgrade`]: struct.Weak.html#method.upgrade
912
+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
911
913
///
912
914
/// # Examples
913
915
///
@@ -926,8 +928,6 @@ impl<T> Default for Weak<T> {
926
928
impl < T : ?Sized > Drop for Weak < T > {
927
929
/// Drops the `Weak` pointer.
928
930
///
929
- /// This will decrement the weak reference count.
930
- ///
931
931
/// # Examples
932
932
///
933
933
/// ```
0 commit comments