@@ -165,18 +165,29 @@ unsafe impl<T: ?Sized + Sync + Send> Sync for Arc<T> {}
165165#[ unstable( feature = "coerce_unsized" , issue = "27732" ) ]
166166impl < T : ?Sized + Unsize < U > , U : ?Sized > CoerceUnsized < Arc < U > > for Arc < T > { }
167167
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>>`.
169171///
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.
172176///
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.
175183///
176- /// See the [`Arc`][arc] documentation for more details .
184+ /// The typical way to obtain a `Weak` pointer is to call [`Arc::downgrade`] .
177185///
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
180191#[ stable( feature = "arc_weak" , since = "1.4.0" ) ]
181192pub struct Weak < T : ?Sized > {
182193 ptr : Shared < ArcInner < T > > ,
@@ -766,14 +777,11 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
766777}
767778
768779impl < 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`].
774782 ///
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
777785 ///
778786 /// # Examples
779787 ///
@@ -798,13 +806,13 @@ impl<T> Weak<T> {
798806}
799807
800808impl < 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.
802811 ///
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.
805813 ///
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
808816 ///
809817 /// # Examples
810818 ///
@@ -865,10 +873,7 @@ impl<T: ?Sized> Weak<T> {
865873
866874#[ stable( feature = "arc_weak" , since = "1.4.0" ) ]
867875impl < 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.
872877 ///
873878 /// # Examples
874879 ///
@@ -900,14 +905,11 @@ impl<T: ?Sized> Clone for Weak<T> {
900905
901906#[ stable( feature = "downgraded_weak" , since = "1.10.0" ) ]
902907impl < 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`].
904910 ///
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
911913 ///
912914 /// # Examples
913915 ///
@@ -926,8 +928,6 @@ impl<T> Default for Weak<T> {
926928impl < T : ?Sized > Drop for Weak < T > {
927929 /// Drops the `Weak` pointer.
928930 ///
929- /// This will decrement the weak reference count.
930- ///
931931 /// # Examples
932932 ///
933933 /// ```
0 commit comments