@@ -16,7 +16,7 @@ use rustc_hash::FxHasher;
16
16
type InternMap < T > = DashMap < Arc < T > , ( ) , BuildHasherDefault < FxHasher > > ;
17
17
18
18
#[ derive( Hash ) ]
19
- pub struct Interned < T : Internable > {
19
+ pub struct Interned < T : Internable + ? Sized > {
20
20
arc : Arc < T > ,
21
21
}
22
22
@@ -52,7 +52,7 @@ impl<T: Internable> Interned<T> {
52
52
}
53
53
}
54
54
55
- impl < T : Internable > Drop for Interned < T > {
55
+ impl < T : Internable + ? Sized > Drop for Interned < T > {
56
56
fn drop ( & mut self ) {
57
57
// When the last `Ref` is dropped, remove the object from the global map.
58
58
if Arc :: strong_count ( & self . arc ) == 2 {
@@ -83,23 +83,23 @@ impl<T: Internable> Drop for Interned<T> {
83
83
}
84
84
85
85
/// Compares interned `Ref`s using pointer equality.
86
- impl < T : Internable > PartialEq for Interned < T > {
86
+ impl < T : Internable + ? Sized > PartialEq for Interned < T > {
87
87
#[ inline]
88
88
fn eq ( & self , other : & Self ) -> bool {
89
89
Arc :: ptr_eq ( & self . arc , & other. arc )
90
90
}
91
91
}
92
92
93
- impl < T : Internable > Eq for Interned < T > { }
93
+ impl < T : Internable + ? Sized > Eq for Interned < T > { }
94
94
95
- impl < T : Internable > AsRef < T > for Interned < T > {
95
+ impl < T : Internable + ? Sized > AsRef < T > for Interned < T > {
96
96
#[ inline]
97
97
fn as_ref ( & self ) -> & T {
98
98
& self . arc
99
99
}
100
100
}
101
101
102
- impl < T : Internable > Deref for Interned < T > {
102
+ impl < T : Internable + ? Sized > Deref for Interned < T > {
103
103
type Target = T ;
104
104
105
105
#[ inline]
@@ -108,40 +108,38 @@ impl<T: Internable> Deref for Interned<T> {
108
108
}
109
109
}
110
110
111
- impl < T : Internable > Clone for Interned < T > {
111
+ impl < T : Internable + ? Sized > Clone for Interned < T > {
112
112
fn clone ( & self ) -> Self {
113
113
Self { arc : self . arc . clone ( ) }
114
114
}
115
115
}
116
116
117
- impl < T : Debug + Internable > Debug for Interned < T > {
117
+ impl < T : Debug + Internable + ? Sized > Debug for Interned < T > {
118
118
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
119
119
( * self . arc ) . fmt ( f)
120
120
}
121
121
}
122
122
123
- pub struct InternStorage < T > {
123
+ pub struct InternStorage < T : ? Sized > {
124
124
map : OnceCell < InternMap < T > > ,
125
125
}
126
126
127
- impl < T > InternStorage < T > {
127
+ impl < T : ? Sized > InternStorage < T > {
128
128
pub const fn new ( ) -> Self {
129
129
Self { map : OnceCell :: new ( ) }
130
130
}
131
131
}
132
132
133
- impl < T : Internable > InternStorage < T > {
133
+ impl < T : Internable + ? Sized > InternStorage < T > {
134
134
fn get ( & self ) -> & InternMap < T > {
135
135
self . map . get_or_init ( DashMap :: default)
136
136
}
137
137
}
138
138
139
- pub trait Internable : Hash + Eq + Sized + ' static {
139
+ pub trait Internable : Hash + Eq + ' static {
140
140
fn storage ( ) -> & ' static InternStorage < Self > ;
141
141
}
142
142
143
- // region:`Internable` implementations
144
-
145
143
macro_rules! impl_internable {
146
144
( $( $t: ty) ,+ $( , ) ? ) => { $(
147
145
impl Internable for $t {
@@ -154,5 +152,3 @@ macro_rules! impl_internable {
154
152
}
155
153
156
154
impl_internable ! ( crate :: type_ref:: TypeRef , crate :: type_ref:: TraitRef , crate :: path:: ModPath ) ;
157
-
158
- // endregion
0 commit comments