@@ -79,17 +79,7 @@ impl<T> From<&Interned<T>> for Interned<T> {
79
79
pub trait Leak {
80
80
/// Creates a static reference to `self`, possibly leaking memory.
81
81
fn leak ( & self ) -> & ' static Self ;
82
- }
83
-
84
- impl Leak for str {
85
- fn leak ( & self ) -> & ' static Self {
86
- let str = self . to_owned ( ) . into_boxed_str ( ) ;
87
- Box :: leak ( str)
88
- }
89
- }
90
82
91
- /// A type that can provide static references to equal values.
92
- pub trait StaticRef {
93
83
/// Returns a static reference to a value equal to `self`, if possible.
94
84
/// This method is used by [`Interner::intern`] to optimize the interning process.
95
85
///
@@ -127,7 +117,12 @@ pub trait StaticRef {
127
117
}
128
118
}
129
119
130
- impl StaticRef for str { }
120
+ impl Leak for str {
121
+ fn leak ( & self ) -> & ' static Self {
122
+ let str = self . to_owned ( ) . into_boxed_str ( ) ;
123
+ Box :: leak ( str)
124
+ }
125
+ }
131
126
132
127
/// A thread-safe interner which can be used to create [`Interned<T>`] from `&T`
133
128
///
@@ -145,7 +140,7 @@ impl<T: ?Sized> Interner<T> {
145
140
}
146
141
}
147
142
148
- impl < T : Leak + StaticRef + Hash + Eq + ?Sized > Interner < T > {
143
+ impl < T : Leak + Hash + Eq + ?Sized > Interner < T > {
149
144
/// Return the [`Interned<T>`] corresponding to `value`.
150
145
///
151
146
/// If it is called the first time for `value`, it will possibly leak the value and return an
@@ -190,23 +185,21 @@ mod tests {
190
185
hash:: { Hash , Hasher } ,
191
186
} ;
192
187
193
- use crate :: intern:: { Interned , Interner , Leak , StaticRef } ;
188
+ use crate :: intern:: { Interned , Interner , Leak } ;
194
189
195
190
#[ test]
196
191
fn zero_sized_type ( ) {
197
192
#[ derive( PartialEq , Eq , Hash , Debug ) ]
198
193
pub struct A ;
199
194
200
- impl StaticRef for A {
201
- fn static_ref ( & self ) -> Option < & ' static Self > {
202
- Some ( & A )
203
- }
204
- }
205
-
206
195
impl Leak for A {
207
196
fn leak ( & self ) -> & ' static Self {
208
197
& A
209
198
}
199
+
200
+ fn static_ref ( & self ) -> Option < & ' static Self > {
201
+ Some ( & A )
202
+ }
210
203
}
211
204
212
205
let interner = Interner :: default ( ) ;
@@ -223,22 +216,20 @@ mod tests {
223
216
Y ,
224
217
}
225
218
226
- impl StaticRef for A {
227
- fn static_ref ( & self ) -> Option < & ' static Self > {
228
- Some ( match self {
229
- A :: X => & A :: X ,
230
- A :: Y => & A :: Y ,
231
- } )
232
- }
233
- }
234
-
235
219
impl Leak for A {
236
220
fn leak ( & self ) -> & ' static Self {
237
221
match self {
238
222
A :: X => & A :: X ,
239
223
A :: Y => & A :: Y ,
240
224
}
241
225
}
226
+
227
+ fn static_ref ( & self ) -> Option < & ' static Self > {
228
+ Some ( match self {
229
+ A :: X => & A :: X ,
230
+ A :: Y => & A :: Y ,
231
+ } )
232
+ }
242
233
}
243
234
244
235
let interner = Interner :: default ( ) ;
0 commit comments