@@ -2034,37 +2034,38 @@ impl<T> [T] {
2034
2034
unsafe { ( from_raw_parts_mut ( ptr, mid) , from_raw_parts_mut ( ptr. add ( mid) , len - mid) ) }
2035
2035
}
2036
2036
2037
- /// Divides one slice into two at an index returning, `None` if slice is too
2038
- /// short.
2037
+ /// Divides one slice into two at an index, returning `None` if the slice is
2038
+ /// too short.
2039
2039
///
2040
- /// The first will contain all indices from `[0, mid)` (excluding
2041
- /// the index `mid` itself) and the second will contain all
2042
- /// indices from `[mid, len)` (excluding the index `len` itself).
2040
+ /// If `mid ≤ len` returns a pair of slices where the first will contain all
2041
+ /// indices from `[0, mid)` (excluding the index `mid` itself) and the
2042
+ /// second will contain all indices from `[mid, len)` (excluding the index
2043
+ /// `len` itself).
2043
2044
///
2044
- /// Returns `None` if `mid > len`.
2045
+ /// Otherwise, if `mid > len`, returns `None `.
2045
2046
///
2046
2047
/// # Examples
2047
2048
///
2048
2049
/// ```
2049
2050
/// #![feature(split_at_checked)]
2050
2051
///
2051
- /// let v = [1, 2, 3, 4, 5, 6];
2052
+ /// let v = [1, - 2, 3, - 4, 5, - 6];
2052
2053
///
2053
2054
/// {
2054
2055
/// let (left, right) = v.split_at_checked(0).unwrap();
2055
2056
/// assert_eq!(left, []);
2056
- /// assert_eq!(right, [1, 2, 3, 4, 5, 6]);
2057
+ /// assert_eq!(right, [1, - 2, 3, - 4, 5, - 6]);
2057
2058
/// }
2058
2059
///
2059
2060
/// {
2060
2061
/// let (left, right) = v.split_at_checked(2).unwrap();
2061
- /// assert_eq!(left, [1, 2]);
2062
- /// assert_eq!(right, [3, 4, 5, 6]);
2062
+ /// assert_eq!(left, [1, - 2]);
2063
+ /// assert_eq!(right, [3, - 4, 5, - 6]);
2063
2064
/// }
2064
2065
///
2065
2066
/// {
2066
2067
/// let (left, right) = v.split_at_checked(6).unwrap();
2067
- /// assert_eq!(left, [1, 2, 3, 4, 5, 6]);
2068
+ /// assert_eq!(left, [1, - 2, 3, - 4, 5, - 6]);
2068
2069
/// assert_eq!(right, []);
2069
2070
/// }
2070
2071
///
@@ -2073,7 +2074,6 @@ impl<T> [T] {
2073
2074
#[ unstable( feature = "split_at_checked" , reason = "new API" , issue = "119128" ) ]
2074
2075
#[ rustc_const_unstable( feature = "split_at_checked" , issue = "119128" ) ]
2075
2076
#[ inline]
2076
- #[ track_caller]
2077
2077
#[ must_use]
2078
2078
pub const fn split_at_checked ( & self , mid : usize ) -> Option < ( & [ T ] , & [ T ] ) > {
2079
2079
if mid <= self . len ( ) {
@@ -2085,14 +2085,15 @@ impl<T> [T] {
2085
2085
}
2086
2086
}
2087
2087
2088
- /// Divides one mutable slice into two at an index, returning `None` if
2088
+ /// Divides one mutable slice into two at an index, returning `None` if the
2089
2089
/// slice is too short.
2090
2090
///
2091
- /// The first will contain all indices from `[0, mid)` (excluding
2092
- /// the index `mid` itself) and the second will contain all
2093
- /// indices from `[mid, len)` (excluding the index `len` itself).
2091
+ /// If `mid ≤ len` returns a pair of slices where the first will contain all
2092
+ /// indices from `[0, mid)` (excluding the index `mid` itself) and the
2093
+ /// second will contain all indices from `[mid, len)` (excluding the index
2094
+ /// `len` itself).
2094
2095
///
2095
- /// Returns `None` if `mid > len`.
2096
+ /// Otherwise, if `mid > len`, returns `None `.
2096
2097
///
2097
2098
/// # Examples
2098
2099
///
@@ -2114,7 +2115,6 @@ impl<T> [T] {
2114
2115
#[ unstable( feature = "split_at_checked" , reason = "new API" , issue = "119128" ) ]
2115
2116
#[ rustc_const_unstable( feature = "split_at_checked" , issue = "119128" ) ]
2116
2117
#[ inline]
2117
- #[ track_caller]
2118
2118
#[ must_use]
2119
2119
pub const fn split_at_mut_checked ( & mut self , mid : usize ) -> Option < ( & mut [ T ] , & mut [ T ] ) > {
2120
2120
if mid <= self . len ( ) {
@@ -2126,164 +2126,6 @@ impl<T> [T] {
2126
2126
}
2127
2127
}
2128
2128
2129
- /// Divides one slice into an array and a remainder slice at an index.
2130
- ///
2131
- /// The array will contain all indices from `[0, N)` (excluding
2132
- /// the index `N` itself) and the slice will contain all
2133
- /// indices from `[N, len)` (excluding the index `len` itself).
2134
- ///
2135
- /// # Panics
2136
- ///
2137
- /// Panics if `N > len`.
2138
- ///
2139
- /// # Examples
2140
- ///
2141
- /// ```
2142
- /// #![feature(split_array)]
2143
- ///
2144
- /// let v = &[1, 2, 3, 4, 5, 6][..];
2145
- ///
2146
- /// {
2147
- /// let (left, right) = v.split_array_ref::<0>();
2148
- /// assert_eq!(left, &[]);
2149
- /// assert_eq!(right, [1, 2, 3, 4, 5, 6]);
2150
- /// }
2151
- ///
2152
- /// {
2153
- /// let (left, right) = v.split_array_ref::<2>();
2154
- /// assert_eq!(left, &[1, 2]);
2155
- /// assert_eq!(right, [3, 4, 5, 6]);
2156
- /// }
2157
- ///
2158
- /// {
2159
- /// let (left, right) = v.split_array_ref::<6>();
2160
- /// assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
2161
- /// assert_eq!(right, []);
2162
- /// }
2163
- /// ```
2164
- #[ unstable( feature = "split_array" , reason = "new API" , issue = "90091" ) ]
2165
- #[ inline]
2166
- #[ track_caller]
2167
- #[ must_use]
2168
- pub fn split_array_ref < const N : usize > ( & self ) -> ( & [ T ; N ] , & [ T ] ) {
2169
- let ( a, b) = self . split_at ( N ) ;
2170
- // SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at)
2171
- unsafe { ( & * ( a. as_ptr ( ) as * const [ T ; N ] ) , b) }
2172
- }
2173
-
2174
- /// Divides one mutable slice into an array and a remainder slice at an index.
2175
- ///
2176
- /// The array will contain all indices from `[0, N)` (excluding
2177
- /// the index `N` itself) and the slice will contain all
2178
- /// indices from `[N, len)` (excluding the index `len` itself).
2179
- ///
2180
- /// # Panics
2181
- ///
2182
- /// Panics if `N > len`.
2183
- ///
2184
- /// # Examples
2185
- ///
2186
- /// ```
2187
- /// #![feature(split_array)]
2188
- ///
2189
- /// let mut v = &mut [1, 0, 3, 0, 5, 6][..];
2190
- /// let (left, right) = v.split_array_mut::<2>();
2191
- /// assert_eq!(left, &mut [1, 0]);
2192
- /// assert_eq!(right, [3, 0, 5, 6]);
2193
- /// left[1] = 2;
2194
- /// right[1] = 4;
2195
- /// assert_eq!(v, [1, 2, 3, 4, 5, 6]);
2196
- /// ```
2197
- #[ unstable( feature = "split_array" , reason = "new API" , issue = "90091" ) ]
2198
- #[ inline]
2199
- #[ track_caller]
2200
- #[ must_use]
2201
- pub fn split_array_mut < const N : usize > ( & mut self ) -> ( & mut [ T ; N ] , & mut [ T ] ) {
2202
- let ( a, b) = self . split_at_mut ( N ) ;
2203
- // SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at_mut)
2204
- unsafe { ( & mut * ( a. as_mut_ptr ( ) as * mut [ T ; N ] ) , b) }
2205
- }
2206
-
2207
- /// Divides one slice into an array and a remainder slice at an index from
2208
- /// the end.
2209
- ///
2210
- /// The slice will contain all indices from `[0, len - N)` (excluding
2211
- /// the index `len - N` itself) and the array will contain all
2212
- /// indices from `[len - N, len)` (excluding the index `len` itself).
2213
- ///
2214
- /// # Panics
2215
- ///
2216
- /// Panics if `N > len`.
2217
- ///
2218
- /// # Examples
2219
- ///
2220
- /// ```
2221
- /// #![feature(split_array)]
2222
- ///
2223
- /// let v = &[1, 2, 3, 4, 5, 6][..];
2224
- ///
2225
- /// {
2226
- /// let (left, right) = v.rsplit_array_ref::<0>();
2227
- /// assert_eq!(left, [1, 2, 3, 4, 5, 6]);
2228
- /// assert_eq!(right, &[]);
2229
- /// }
2230
- ///
2231
- /// {
2232
- /// let (left, right) = v.rsplit_array_ref::<2>();
2233
- /// assert_eq!(left, [1, 2, 3, 4]);
2234
- /// assert_eq!(right, &[5, 6]);
2235
- /// }
2236
- ///
2237
- /// {
2238
- /// let (left, right) = v.rsplit_array_ref::<6>();
2239
- /// assert_eq!(left, []);
2240
- /// assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
2241
- /// }
2242
- /// ```
2243
- #[ unstable( feature = "split_array" , reason = "new API" , issue = "90091" ) ]
2244
- #[ inline]
2245
- #[ must_use]
2246
- pub fn rsplit_array_ref < const N : usize > ( & self ) -> ( & [ T ] , & [ T ; N ] ) {
2247
- assert ! ( N <= self . len( ) ) ;
2248
- let ( a, b) = self . split_at ( self . len ( ) - N ) ;
2249
- // SAFETY: b points to [T; N]? Yes it's [T] of length N (checked by split_at)
2250
- unsafe { ( a, & * ( b. as_ptr ( ) as * const [ T ; N ] ) ) }
2251
- }
2252
-
2253
- /// Divides one mutable slice into an array and a remainder slice at an
2254
- /// index from the end.
2255
- ///
2256
- /// The slice will contain all indices from `[0, len - N)` (excluding
2257
- /// the index `N` itself) and the array will contain all
2258
- /// indices from `[len - N, len)` (excluding the index `len` itself).
2259
- ///
2260
- /// # Panics
2261
- ///
2262
- /// Panics if `N > len`.
2263
- ///
2264
- /// # Examples
2265
- ///
2266
- /// ```
2267
- /// #![feature(split_array)]
2268
- ///
2269
- /// let mut v = &mut [1, 0, 3, 0, 5, 6][..];
2270
- /// let (left, right) = v.rsplit_array_mut::<4>();
2271
- /// assert_eq!(left, [1, 0]);
2272
- /// assert_eq!(right, &mut [3, 0, 5, 6]);
2273
- /// left[1] = 2;
2274
- /// right[1] = 4;
2275
- /// assert_eq!(v, [1, 2, 3, 4, 5, 6]);
2276
- /// ```
2277
- #[ unstable( feature = "split_array" , reason = "new API" , issue = "90091" ) ]
2278
- #[ inline]
2279
- #[ must_use]
2280
- pub fn rsplit_array_mut < const N : usize > ( & mut self ) -> ( & mut [ T ] , & mut [ T ; N ] ) {
2281
- assert ! ( N <= self . len( ) ) ;
2282
- let ( a, b) = self . split_at_mut ( self . len ( ) - N ) ;
2283
- // SAFETY: b points to [T; N]? Yes it's [T] of length N (checked by split_at_mut)
2284
- unsafe { ( a, & mut * ( b. as_mut_ptr ( ) as * mut [ T ; N ] ) ) }
2285
- }
2286
-
2287
2129
/// Returns an iterator over subslices separated by elements that match
2288
2130
/// `pred`. The matched element is not contained in the subslices.
2289
2131
///
0 commit comments