rust/src/liballoc
bors f29b4fbd74 Auto merge of #56696 - jonas-schievink:weak-counts, r=alexcrichton
Implement Weak::{strong_count, weak_count}

The counters are also useful on `Weak`, not just on strong references (`Rc` or `Arc`).

In situations where there are still strong references around, you can also get these counts by temporarily upgrading and adjusting the values accordingly. Using the methods introduced here is simpler to do, less error-prone (since you can't forget to adjust the counts), can also be used when no strong references are around anymore, and might be more efficient due to not having to temporarily create an `Rc`.

This is mainly useful in assertions or tests of complex data structures. Data structures might have internal invariants that make them the sole owner of a `Weak` pointer, and an assertion on the weak count could be used to ensure that this indeed happens as expected. Due to the presence of `Weak::upgrade`, the `strong_count` becomes less useful, but it still seems worthwhile to mirror the API of `Rc`.

TODO:
* [X] Tracking issue - https://github.com/rust-lang/rust/issues/57977

Closes https://github.com/rust-lang/rust/issues/50158
2019-01-31 19:20:14 +00:00
..
benches Bump bootstrap compiler to 1.33 beta 2019-01-26 08:02:08 -07:00
collections override VecDeque's Iter::try_fold 2019-01-30 09:11:17 +01:00
tests override VecDeque's Iter::try_fold 2019-01-30 09:11:17 +01:00
alloc.rs Remove licenses 2018-12-25 21:08:33 -07:00
borrow.rs liballoc: remove unneeded allow(deprecated) 2019-01-28 10:39:49 +01:00
boxed.rs impl Generator for Pin<Box<Generator>> 2019-01-27 22:58:59 +01:00
boxed_test.rs Remove licenses 2018-12-25 21:08:33 -07:00
Cargo.toml fix deprecation warnings in liballoc benches 2018-12-21 11:33:29 +01:00
fmt.rs Mention ToString in std::fmt docs 2018-12-29 19:17:03 -05:00
lib.rs override VecDeque's Iter::try_fold 2019-01-30 09:11:17 +01:00
macros.rs Mention ToString in std::fmt docs 2018-12-29 19:17:03 -05:00
prelude.rs Remove licenses 2018-12-25 21:08:33 -07:00
raw_vec.rs RawVec doesn't always abort on allocation errors 2019-01-08 17:21:30 -05:00
rc.rs Auto merge of #56696 - jonas-schievink:weak-counts, r=alexcrichton 2019-01-31 19:20:14 +00:00
slice.rs Remove licenses 2018-12-25 21:08:33 -07:00
str.rs Remove licenses 2018-12-25 21:08:33 -07:00
string.rs Remove licenses 2018-12-25 21:08:33 -07:00
sync.rs Auto merge of #56696 - jonas-schievink:weak-counts, r=alexcrichton 2019-01-31 19:20:14 +00:00
task.rs Remove licenses 2018-12-25 21:08:33 -07:00
vec.rs Add a debug_assert to Vec::set_len 2019-01-13 22:40:25 -08:00