@@ -124,6 +124,7 @@ impl<K, V> Slice<K, V> {
124124 /// Divides one slice into two at an index.
125125 ///
126126 /// ***Panics*** if `index > len`.
127+ /// For a non-panicking alternative see [`split_at_checked`][Self::split_at_checked].
127128 #[ track_caller]
128129 pub fn split_at ( & self , index : usize ) -> ( & Self , & Self ) {
129130 let ( first, second) = self . entries . split_at ( index) ;
@@ -133,12 +134,29 @@ impl<K, V> Slice<K, V> {
133134 /// Divides one mutable slice into two at an index.
134135 ///
135136 /// ***Panics*** if `index > len`.
137+ /// For a non-panicking alternative see [`split_at_mut_checked`][Self::split_at_mut_checked].
136138 #[ track_caller]
137139 pub fn split_at_mut ( & mut self , index : usize ) -> ( & mut Self , & mut Self ) {
138140 let ( first, second) = self . entries . split_at_mut ( index) ;
139141 ( Self :: from_mut_slice ( first) , Self :: from_mut_slice ( second) )
140142 }
141143
144+ /// Divides one slice into two at an index.
145+ ///
146+ /// 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) ) )
150+ }
151+
152+ /// Divides one mutable slice into two at an index.
153+ ///
154+ /// Returns `None` if `index > len`.
155+ pub fn split_at_mut_checked ( & mut self , index : usize ) -> Option < ( & mut Self , & mut Self ) > {
156+ let ( first, second) = self . entries . split_at_mut_checked ( index) ?;
157+ Some ( ( Self :: from_mut_slice ( first) , Self :: from_mut_slice ( second) ) )
158+ }
159+
142160 /// Returns the first key-value pair and the rest of the slice,
143161 /// or `None` if it is empty.
144162 pub fn split_first ( & self ) -> Option < ( ( & K , & V ) , & Self ) > {
0 commit comments