Skip to content

Commit 9f17c85

Browse files
committed
Use a more standard way to seal MutableKeys
Ref: https://rust-lang.github.io/api-guidelines/future-proofing.html
1 parent b50fbd9 commit 9f17c85

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/mutable_keys.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use core::hash::{BuildHasher, Hash};
22

33
use super::{Bucket, Entries, Equivalent, IndexMap};
44

5-
pub struct PrivateMarker {}
6-
75
/// Opt-in mutable access to keys.
86
///
97
/// These methods expose `&mut K`, mutable references to the key as it is stored
@@ -16,7 +14,9 @@ pub struct PrivateMarker {}
1614
/// implementing PartialEq, Eq, or Hash incorrectly would be).
1715
///
1816
/// `use` this trait to enable its methods for `IndexMap`.
19-
pub trait MutableKeys {
17+
///
18+
/// This trait is sealed and cannot be implemented for types outside this crate.
19+
pub trait MutableKeys: private::Sealed {
2020
type Key;
2121
type Value;
2222

@@ -47,12 +47,6 @@ pub trait MutableKeys {
4747
fn retain2<F>(&mut self, keep: F)
4848
where
4949
F: FnMut(&mut Self::Key, &mut Self::Value) -> bool;
50-
51-
#[doc(hidden)]
52-
/// This method is not useful in itself – it is there to “seal” the trait
53-
/// for external implementation, so that we can add methods without
54-
/// causing breaking changes.
55-
fn __private_marker(&self) -> PrivateMarker;
5650
}
5751

5852
/// Opt-in mutable access to keys.
@@ -88,8 +82,10 @@ where
8882
{
8983
self.retain_mut(keep)
9084
}
85+
}
9186

92-
fn __private_marker(&self) -> PrivateMarker {
93-
PrivateMarker {}
94-
}
87+
mod private {
88+
pub trait Sealed {}
89+
90+
impl<K, V, S> Sealed for super::IndexMap<K, V, S> {}
9591
}

0 commit comments

Comments
 (0)