@@ -717,20 +717,32 @@ impl<K, V, S> IndexMap<K, V, S> {
717
717
self . as_entries_mut ( ) . get_mut ( index) . map ( Bucket :: muts)
718
718
}
719
719
720
+ /// Get the first key-value pair
721
+ ///
722
+ /// Computes in **O(1)** time.
720
723
pub fn first ( & self ) -> Option < ( & K , & V ) > {
721
724
self . as_entries ( ) . first ( ) . map ( Bucket :: refs)
722
725
}
723
726
724
- pub fn first_mut ( & mut self ) -> Option < ( & mut K , & mut V ) > {
725
- self . as_entries_mut ( ) . first_mut ( ) . map ( Bucket :: muts)
727
+ /// Get the first key-value pair, with mutable access to the value
728
+ ///
729
+ /// Computes in **O(1)** time.
730
+ pub fn first_mut ( & mut self ) -> Option < ( & K , & mut V ) > {
731
+ self . as_entries_mut ( ) . first_mut ( ) . map ( Bucket :: ref_mut)
726
732
}
727
733
734
+ /// Get the last key-value pair
735
+ ///
736
+ /// Computes in **O(1)** time.
728
737
pub fn last ( & self ) -> Option < ( & K , & V ) > {
729
738
self . as_entries ( ) . last ( ) . map ( Bucket :: refs)
730
739
}
731
740
732
- pub fn last_mut ( & mut self ) -> Option < ( & mut K , & mut V ) > {
733
- self . as_entries_mut ( ) . last_mut ( ) . map ( Bucket :: muts)
741
+ /// Get the last key-value pair, with mutable access to the value
742
+ ///
743
+ /// Computes in **O(1)** time.
744
+ pub fn last_mut ( & mut self ) -> Option < ( & K , & mut V ) > {
745
+ self . as_entries_mut ( ) . last_mut ( ) . map ( Bucket :: ref_mut)
734
746
}
735
747
736
748
/// Remove the key-value pair by index
0 commit comments