@@ -102,8 +102,12 @@ impl<K, V> Slice<K, V> {
102102 }
103103
104104 /// Get the first key-value pair.
105- pub fn first ( & self ) -> Option < ( & K , & V ) > {
106- self . entries . first ( ) . map ( Bucket :: refs)
105+ pub const fn first ( & self ) -> Option < ( & K , & V ) > {
106+ if let [ first, ..] = & self . entries {
107+ Some ( first. refs ( ) )
108+ } else {
109+ None
110+ }
107111 }
108112
109113 /// Get the first key-value pair, with mutable access to the value.
@@ -112,8 +116,12 @@ impl<K, V> Slice<K, V> {
112116 }
113117
114118 /// Get the last key-value pair.
115- pub fn last ( & self ) -> Option < ( & K , & V ) > {
116- self . entries . last ( ) . map ( Bucket :: refs)
119+ pub const fn last ( & self ) -> Option < ( & K , & V ) > {
120+ if let [ .., last] = & self . entries {
121+ Some ( last. refs ( ) )
122+ } else {
123+ None
124+ }
117125 }
118126
119127 /// Get the last key-value pair, with mutable access to the value.
@@ -126,7 +134,7 @@ impl<K, V> Slice<K, V> {
126134 /// ***Panics*** if `index > len`.
127135 /// For a non-panicking alternative see [`split_at_checked`][Self::split_at_checked].
128136 #[ track_caller]
129- pub fn split_at ( & self , index : usize ) -> ( & Self , & Self ) {
137+ pub const fn split_at ( & self , index : usize ) -> ( & Self , & Self ) {
130138 let ( first, second) = self . entries . split_at ( index) ;
131139 ( Self :: from_slice ( first) , Self :: from_slice ( second) )
132140 }
@@ -144,9 +152,12 @@ impl<K, V> Slice<K, V> {
144152 /// Divides one slice into two at an index.
145153 ///
146154 /// Returns `None` if `index > len`.
147- pub fn split_at_checked ( & self , index : usize ) -> Option < ( & Self , & Self ) > {
148- let ( first, second) = self . entries . split_at_checked ( index) ?;
149- Some ( ( Self :: from_slice ( first) , Self :: from_slice ( second) ) )
155+ pub const fn split_at_checked ( & self , index : usize ) -> Option < ( & Self , & Self ) > {
156+ if let Some ( ( first, second) ) = self . entries . split_at_checked ( index) {
157+ Some ( ( Self :: from_slice ( first) , Self :: from_slice ( second) ) )
158+ } else {
159+ None
160+ }
150161 }
151162
152163 /// Divides one mutable slice into two at an index.
@@ -159,7 +170,7 @@ impl<K, V> Slice<K, V> {
159170
160171 /// Returns the first key-value pair and the rest of the slice,
161172 /// or `None` if it is empty.
162- pub fn split_first ( & self ) -> Option < ( ( & K , & V ) , & Self ) > {
173+ pub const fn split_first ( & self ) -> Option < ( ( & K , & V ) , & Self ) > {
163174 if let [ first, rest @ ..] = & self . entries {
164175 Some ( ( first. refs ( ) , Self :: from_slice ( rest) ) )
165176 } else {
@@ -179,7 +190,7 @@ impl<K, V> Slice<K, V> {
179190
180191 /// Returns the last key-value pair and the rest of the slice,
181192 /// or `None` if it is empty.
182- pub fn split_last ( & self ) -> Option < ( ( & K , & V ) , & Self ) > {
193+ pub const fn split_last ( & self ) -> Option < ( ( & K , & V ) , & Self ) > {
183194 if let [ rest @ .., last] = & self . entries {
184195 Some ( ( last. refs ( ) , Self :: from_slice ( rest) ) )
185196 } else {
0 commit comments