pub(crate) fn remove_entry_by_slot(&mut self, slot: u32) -> Option<(Index, T)> {
        let entry = self.storage.get_mut(slot as usize)?;

        match entry {
            Entry::Occupied(occupied) => {
                // Construct the index that would be used to access this entry.
                let index = Index {
                    generation: occupied.generation,
                    slot,
                };

                // This occupied entry will be replaced with an empty one of the
                // same generation. Generation will be incremented on the next
                // insert.
                let next_entry = Entry::Empty(EmptyEntry {
                    generation: occupied.generation,
                    next_free: self.first_free,
                });

                // Swap new entry into place and consume the old one.
                let old_entry = replace(entry, next_entry);
                let value = old_entry.into_value().unwrap_or_else(|| unreachable!());

                // Set this entry as the next one that should be inserted into,
                // should an insertion happen.
                self.first_free = Some(FreePointer::from_slot(slot));

                self.len = self.len.checked_sub(1).unwrap_or_else(|| unreachable!());

                Some((index, value))
            }
            _ => None,
        }
    }
/// This method is a lot like `remove`, but takes no generation. It's used
/// as part of `drain` and can likely be exposed as a public API eventually.
This method is a lot like `remove`, but takes no generation. It's used
as part of `drain` and can likely be exposed as a public API eventually.
This method is a lot like ` remove ` but takes no generation . It ' s used as part of ` drain ` and can likely be exposed as a public API eventually .
pub(crate) fn remove_entry_by_slot(&mut self, slot: u32) -> Option<(Index, T)> {
        let entry = self.storage.get_mut(slot as usize)?;
        match entry {
            Entry::Occupied(occupied) => {
                // Construct the index that would be used to access this entry.
                let index = Index {
                    generation: occupied.generation,
                    slot,
                };
                // This occupied entry will be replaced with an empty one of the
                // same generation. Generation will be incremented on the next
                // insert.
                let next_entry = Entry::Empty(EmptyEntry {
                    generation: occupied.generation,
                    next_free: self.first_free,
                });
                // Swap new entry into place and consume the old one.
                let old_entry = replace(entry, next_entry);
                let value = old_entry.into_value().unwrap_or_else(|| unreachable!());
                // Set this entry as the next one that should be inserted into,
                // should an insertion happen.
                self.first_free = Some(FreePointer::from_slot(slot));
                self.len = self.len.checked_sub(1).unwrap_or_else(|| unreachable!());
                Some((index, value))
            }
            _ => None,
        }
    }
pub ( crate ) fn remove_entry_by_slot ( & mut self , slot : u32 ) -> Option < ( Index , T ) > { let entry = self . storage . get_mut ( slot as usize ) ? ; match entry { Entry :: Occupied ( occupied ) => { // Construct the index that would be used to access this entry. let index = Index { generation : occupied . generation , slot , } ; // This occupied entry will be replaced with an empty one of the // same generation. Generation will be incremented on the next // insert. let next_entry = Entry :: Empty ( EmptyEntry { generation : occupied . generation , next_free : self . first_free , } ) ; // Swap new entry into place and consume the old one. let old_entry = replace ( entry , next_entry ) ; let value = old_entry . into_value ( ) . unwrap_or_else ( | | unreachable ! ( ) ) ; // Set this entry as the next one that should be inserted into, // should an insertion happen. self . first_free = Some ( FreePointer :: from_slot ( slot ) ) ; self . len = self . len . checked_sub ( 1 ) . unwrap_or_else ( | | unreachable ! ( ) ) ; Some ( ( index , value ) ) } _ => None , } }
This method is a lot like `remove`, but takes no generation.
This method is a lot like ` remove ` but takes no generation .
&mut self
slot
u32
&mut self
slot
u32