Skip to content

Commit c33cdb2

Browse files
authored
Merge pull request #87 from ShaneEverittM/drop-behavior-const
Change DropBehavior to have associated const instead of function.
2 parents 7effaaa + 1f651e2 commit c33cdb2

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

evmap/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ indexmap = { version = "1.1.0", optional = true }
2626
smallvec = "1.0.0"
2727
hashbag = "0.1.2"
2828
rand = { version = "0.7", default-features = false, features = ["alloc"], optional = true }
29-
left-right = "0.10.0"
29+
left-right = { path = "../left-right", version = "0.10.0" }
3030

3131
[dev-dependencies]
3232
quickcheck = "0.9"

evmap/src/aliasing.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@ pub struct NoDrop;
1818
pub(crate) struct DoDrop;
1919

2020
impl DropBehavior for NoDrop {
21-
fn do_drop() -> bool {
22-
false
23-
}
21+
const DO_DROP: bool = false;
2422
}
2523
impl DropBehavior for DoDrop {
26-
fn do_drop() -> bool {
27-
true
28-
}
24+
const DO_DROP: bool = true;
2925
}

left-right/src/aliasing.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! trait. The basic flow of using it is going to go as follows.
55
//!
66
//! 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
88
//! [`Absorb::absorb_first`], you then simply drop any removed `Aliased<T, D>` as normal. The
99
//! backing `T` will not be dropped.
1010
//!
@@ -20,7 +20,7 @@
2020
//! &mut DataStructure<Aliased<T, D2>>
2121
//! ```
2222
//!
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
2424
//! _will_ drop the inner `T`, but this should be safe since the only other alias was dropped in
2525
//! `absorb_first`. This is where the invariant that `absorb_*` is deterministic becomes extremely
2626
//! important!
@@ -138,9 +138,8 @@ use crate::Absorb;
138138

139139
/// Dictates the dropping behavior for the implementing type when used with [`Aliased`].
140140
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;
144143
}
145144

146145
/// A `T` that is aliased.
@@ -174,7 +173,7 @@ where
174173
/// # Safety
175174
///
176175
/// 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
178177
/// as no `&mut T` is ever given out while some `Aliased<T>` may still be used. The returned
179178
/// type assumes that it is always safe to dereference into `&T`, which would not be true if
180179
/// either of those invariants were broken.
@@ -242,7 +241,7 @@ where
242241
D: DropBehavior,
243242
{
244243
fn drop(&mut self) {
245-
if D::do_drop() {
244+
if D::DO_DROP {
246245
// safety:
247246
// MaybeUninit<T> was created from a valid T.
248247
// That T has not been dropped (getting a Aliased<T, DoDrop> is unsafe).

0 commit comments

Comments
 (0)