Skip to content

Commit 4849b16

Browse files
committed
Make use of RFC2145 type privacy for sealed traits
1 parent cfff4b7 commit 4849b16

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,11 @@ rustdoc-args = ["--cfg", "docsrs"]
6161
[workspace]
6262
members = ["test-nostd", "test-serde", "test-sval"]
6363

64+
[lints.rust]
65+
private-bounds = "deny"
66+
private-interfaces = "deny"
67+
unnameable-types = "deny"
68+
unreachable-pub = "deny"
69+
6470
[lints.clippy]
6571
style = "allow"

src/map/core/raw_entry_v1.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use hashbrown::hash_table;
2020
/// Opt-in access to the experimental raw entry API.
2121
///
2222
/// See the [`raw_entry_v1`][self] module documentation for more information.
23-
pub trait RawEntryApiV1<K, V, S>: private::Sealed {
23+
#[expect(private_bounds)]
24+
pub trait RawEntryApiV1<K, V, S>: Sealed {
2425
/// Creates a raw immutable entry builder for the [`IndexMap`].
2526
///
2627
/// Raw entries provide the lowest level of control for searching and
@@ -646,8 +647,6 @@ impl<'a, K, V, S> RawVacantEntryMut<'a, K, V, S> {
646647
}
647648
}
648649

649-
mod private {
650-
pub trait Sealed {}
650+
trait Sealed {}
651651

652-
impl<K, V, S> Sealed for super::IndexMap<K, V, S> {}
653-
}
652+
impl<K, V, S> Sealed for IndexMap<K, V, S> {}

src/map/mutable.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use super::{
1818
/// `use` this trait to enable its methods for `IndexMap`.
1919
///
2020
/// This trait is sealed and cannot be implemented for types outside this crate.
21-
pub trait MutableKeys: private::Sealed {
21+
#[expect(private_bounds)]
22+
pub trait MutableKeys: Sealed {
2223
type Key;
2324
type Value;
2425

@@ -103,7 +104,8 @@ where
103104
/// `use` this trait to enable its methods for `Entry`.
104105
///
105106
/// This trait is sealed and cannot be implemented for types outside this crate.
106-
pub trait MutableEntryKey: private::Sealed {
107+
#[expect(private_bounds)]
108+
pub trait MutableEntryKey: Sealed {
107109
type Key;
108110

109111
/// Gets a mutable reference to the entry's key, either within the map if occupied,
@@ -154,12 +156,10 @@ impl<K, V> MutableEntryKey for IndexedEntry<'_, K, V> {
154156
}
155157
}
156158

157-
mod private {
158-
pub trait Sealed {}
159+
trait Sealed {}
159160

160-
impl<K, V, S> Sealed for super::IndexMap<K, V, S> {}
161-
impl<K, V> Sealed for super::Entry<'_, K, V> {}
162-
impl<K, V> Sealed for super::OccupiedEntry<'_, K, V> {}
163-
impl<K, V> Sealed for super::VacantEntry<'_, K, V> {}
164-
impl<K, V> Sealed for super::IndexedEntry<'_, K, V> {}
165-
}
161+
impl<K, V, S> Sealed for IndexMap<K, V, S> {}
162+
impl<K, V> Sealed for Entry<'_, K, V> {}
163+
impl<K, V> Sealed for OccupiedEntry<'_, K, V> {}
164+
impl<K, V> Sealed for VacantEntry<'_, K, V> {}
165+
impl<K, V> Sealed for IndexedEntry<'_, K, V> {}

src/set/mutable.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ use crate::map::MutableKeys;
1717
/// `use` this trait to enable its methods for `IndexSet`.
1818
///
1919
/// This trait is sealed and cannot be implemented for types outside this crate.
20-
pub trait MutableValues: private::Sealed {
20+
#[expect(private_bounds)]
21+
pub trait MutableValues: Sealed {
2122
type Value;
2223

2324
/// Return item index and mutable reference to the value
@@ -79,8 +80,6 @@ where
7980
}
8081
}
8182

82-
mod private {
83-
pub trait Sealed {}
83+
trait Sealed {}
8484

85-
impl<T, S> Sealed for super::IndexSet<T, S> {}
86-
}
85+
impl<T, S> Sealed for IndexSet<T, S> {}

0 commit comments

Comments
 (0)