|
4 | 4 | //! trait. The basic flow of using it is going to go as follows. |
5 | 5 | //! |
6 | 6 | //! In general, each value in your data structure should be stored wrapped in an `Aliased`, with an |
7 | | -//! associated type `D` that has `DropBehavior::do_drop` return `false`. In |
| 7 | +//! associated type `D` that has `DropBehavior::DO_DROP` set to `false`. In |
8 | 8 | //! [`Absorb::absorb_first`], you then simply drop any removed `Aliased<T, D>` as normal. The |
9 | 9 | //! backing `T` will not be dropped. |
10 | 10 | //! |
|
20 | 20 | //! &mut DataStructure<Aliased<T, D2>> |
21 | 21 | //! ``` |
22 | 22 | //! |
23 | | -//! where `<D2 as DropBehavior>::do_drop` returns `true`. This time, any `Aliased<T>` that you drop |
| 23 | +//! where `<D2 as DropBehavior>::DO_DROP` is `true`. This time, any `Aliased<T>` that you drop |
24 | 24 | //! _will_ drop the inner `T`, but this should be safe since the only other alias was dropped in |
25 | 25 | //! `absorb_first`. This is where the invariant that `absorb_*` is deterministic becomes extremely |
26 | 26 | //! important! |
@@ -138,9 +138,8 @@ use crate::Absorb; |
138 | 138 |
|
139 | 139 | /// Dictates the dropping behavior for the implementing type when used with [`Aliased`]. |
140 | 140 | pub trait DropBehavior { |
141 | | - /// An [`Aliased<T, D>`](Aliased) will drop its inner `T` if and only if `D::do_drop` returns |
142 | | - /// `true`. |
143 | | - fn do_drop() -> bool; |
| 141 | + /// An [`Aliased<T, D>`](Aliased) will drop its inner `T` if and only if `D::DO_DROP` is `true` |
| 142 | + const DO_DROP: bool; |
144 | 143 | } |
145 | 144 |
|
146 | 145 | /// A `T` that is aliased. |
@@ -174,7 +173,7 @@ where |
174 | 173 | /// # Safety |
175 | 174 | /// |
176 | 175 | /// This method is only safe to call as long as you ensure that the alias is never used after |
177 | | - /// an `Aliased<T, D>` of `self` where `D::do_drop` returns `true` is dropped, **and** as long |
| 176 | + /// an `Aliased<T, D>` of `self` where `D::DO_DROP` is `true` is dropped, **and** as long |
178 | 177 | /// as no `&mut T` is ever given out while some `Aliased<T>` may still be used. The returned |
179 | 178 | /// type assumes that it is always safe to dereference into `&T`, which would not be true if |
180 | 179 | /// either of those invariants were broken. |
@@ -242,7 +241,7 @@ where |
242 | 241 | D: DropBehavior, |
243 | 242 | { |
244 | 243 | fn drop(&mut self) { |
245 | | - if D::do_drop() { |
| 244 | + if D::DO_DROP { |
246 | 245 | // safety: |
247 | 246 | // MaybeUninit<T> was created from a valid T. |
248 | 247 | // That T has not been dropped (getting a Aliased<T, DoDrop> is unsafe). |
|
0 commit comments