120
120
//! }
121
121
//! ```
122
122
123
+ #![ no_std]
123
124
#![ forbid( unsafe_code) ]
124
125
#![ deny( missing_docs, missing_debug_implementations) ]
125
126
126
- use std:: num:: NonZeroU32 ;
127
+ extern crate alloc;
128
+
129
+ use alloc:: vec:: Vec ;
130
+ use core:: fmt;
131
+ use core:: num:: NonZeroU32 ;
127
132
128
133
/// An identifier for an allocated value inside a `slab`.
129
134
#[ derive( Clone , Copy , PartialEq , Eq , Hash ) ]
130
135
#[ repr( transparent) ]
131
136
pub struct Id ( EntryIndex ) ;
132
137
133
- impl std :: fmt:: Debug for Id {
134
- fn fmt ( & self , f : & mut std :: fmt:: Formatter < ' _ > ) -> std :: fmt:: Result {
138
+ impl fmt:: Debug for Id {
139
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
135
140
f. debug_tuple ( "Id" ) . field ( & self . 0 . index ( ) ) . finish ( )
136
141
}
137
142
}
@@ -167,11 +172,11 @@ pub struct Slab<T> {
167
172
len : u32 ,
168
173
}
169
174
170
- impl < T > std :: fmt:: Debug for Slab < T >
175
+ impl < T > fmt:: Debug for Slab < T >
171
176
where
172
- T : std :: fmt:: Debug ,
177
+ T : fmt:: Debug ,
173
178
{
174
- fn fmt ( & self , f : & mut std :: fmt:: Formatter < ' _ > ) -> std :: fmt:: Result {
179
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
175
180
f. debug_map ( ) . entries ( self . iter ( ) ) . finish ( )
176
181
}
177
182
}
@@ -218,7 +223,7 @@ impl<T> Default for Slab<T> {
218
223
}
219
224
}
220
225
221
- impl < T > std :: ops:: Index < Id > for Slab < T > {
226
+ impl < T > core :: ops:: Index < Id > for Slab < T > {
222
227
type Output = T ;
223
228
224
229
#[ inline]
@@ -228,7 +233,7 @@ impl<T> std::ops::Index<Id> for Slab<T> {
228
233
}
229
234
}
230
235
231
- impl < T > std :: ops:: IndexMut < Id > for Slab < T > {
236
+ impl < T > core :: ops:: IndexMut < Id > for Slab < T > {
232
237
#[ inline]
233
238
fn index_mut ( & mut self , id : Id ) -> & mut Self :: Output {
234
239
self . get_mut ( id)
@@ -282,7 +287,7 @@ impl<T> Slab<T> {
282
287
// we add some amount of minimum additional capacity, since doubling
283
288
// zero capacity isn't useful.
284
289
const MIN_CAPACITY : usize = 16 ;
285
- let additional = std :: cmp:: max ( self . entries . capacity ( ) , MIN_CAPACITY ) ;
290
+ let additional = core :: cmp:: max ( self . entries . capacity ( ) , MIN_CAPACITY ) ;
286
291
self . reserve ( additional) ;
287
292
}
288
293
@@ -419,7 +424,7 @@ impl<T> Slab<T> {
419
424
/// deallocate an arbitrary value.
420
425
#[ inline]
421
426
pub fn dealloc ( & mut self , id : Id ) -> T {
422
- let entry = std :: mem:: replace (
427
+ let entry = core :: mem:: replace (
423
428
self . entries
424
429
. get_mut ( id. 0 . index ( ) )
425
430
. expect ( "id from a different slab" ) ,
@@ -428,7 +433,7 @@ impl<T> Slab<T> {
428
433
match entry {
429
434
Entry :: Free { .. } => panic ! ( "attempt to deallocate an entry that is already vacant" ) ,
430
435
Entry :: Occupied ( value) => {
431
- let next_free = std :: mem:: replace ( & mut self . free , Some ( id. 0 ) ) ;
436
+ let next_free = core :: mem:: replace ( & mut self . free , Some ( id. 0 ) ) ;
432
437
self . entries [ id. 0 . index ( ) ] = Entry :: Free { next_free } ;
433
438
self . len -= 1 ;
434
439
value
0 commit comments