@@ -274,6 +274,12 @@ pub mod details {
274
274
}
275
275
}
276
276
277
+ pub ( crate ) unsafe fn next_free_key_impl ( & self ) -> Option < SlotMapKey > {
278
+ self . idx_to_data_next_free_index
279
+ . peek_impl ( )
280
+ . map ( |v| SlotMapKey :: new ( * v) )
281
+ }
282
+
277
283
pub ( crate ) fn len_impl ( & self ) -> usize {
278
284
self . len
279
285
}
@@ -386,6 +392,12 @@ pub mod details {
386
392
unsafe { self . remove_impl ( key) }
387
393
}
388
394
395
+ /// Returns the [`SlotMapKey`] that will be used when the user calls
396
+ /// [`SlotMap::insert()`]. If the [`SlotMap`] is full it returns [`None`].
397
+ pub fn next_free_key ( & self ) -> Option < SlotMapKey > {
398
+ unsafe { self . next_free_key_impl ( ) }
399
+ }
400
+
389
401
/// Returns the number of stored values.
390
402
pub fn len ( & self ) -> usize {
391
403
self . len_impl ( )
@@ -493,6 +505,17 @@ pub mod details {
493
505
self . remove_impl ( key)
494
506
}
495
507
508
+ /// Returns the [`SlotMapKey`] that will be used when the user calls
509
+ /// [`SlotMap::insert()`]. If the [`SlotMap`] is full it returns [`None`].
510
+ ///
511
+ /// # Safety
512
+ ///
513
+ /// * [`RelocatableSlotMap::init()`] must be called once before
514
+ ///
515
+ pub unsafe fn next_free_key ( & self ) -> Option < SlotMapKey > {
516
+ self . next_free_key_impl ( )
517
+ }
518
+
496
519
/// Returns the number of stored values.
497
520
pub fn len ( & self ) -> usize {
498
521
self . len_impl ( )
@@ -607,6 +630,12 @@ impl<T, const CAPACITY: usize> FixedSizeSlotMap<T, CAPACITY> {
607
630
unsafe { self . state . remove_impl ( key) }
608
631
}
609
632
633
+ /// Returns the [`SlotMapKey`] that will be used when the user calls
634
+ /// [`SlotMap::insert()`]. If the [`SlotMap`] is full it returns [`None`].
635
+ pub fn next_free_key ( & self ) -> Option < SlotMapKey > {
636
+ unsafe { self . state . next_free_key_impl ( ) }
637
+ }
638
+
610
639
/// Returns the number of stored values.
611
640
pub fn len ( & self ) -> usize {
612
641
self . state . len_impl ( )
0 commit comments