@@ -367,6 +367,8 @@ impl<T> [T] {
367367 /// first[1] = 4;
368368 /// }
369369 /// assert_eq!(x, &[5, 4, 2]);
370+ ///
371+ /// assert_eq!(None, x.first_chunk_mut::<4>());
370372 /// ```
371373 #[ unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
372374 #[ rustc_const_unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
@@ -397,6 +399,8 @@ impl<T> [T] {
397399 /// assert_eq!(first, &[0, 1]);
398400 /// assert_eq!(elements, &[2]);
399401 /// }
402+ ///
403+ /// assert_eq!(None, x.split_first_chunk::<4>());
400404 /// ```
401405 #[ unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
402406 #[ rustc_const_unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
@@ -432,6 +436,8 @@ impl<T> [T] {
432436 /// elements[0] = 5;
433437 /// }
434438 /// assert_eq!(x, &[3, 4, 5]);
439+ ///
440+ /// assert_eq!(None, x.split_first_chunk_mut::<4>());
435441 /// ```
436442 #[ unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
437443 #[ rustc_const_unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
@@ -467,6 +473,8 @@ impl<T> [T] {
467473 /// assert_eq!(elements, &[0]);
468474 /// assert_eq!(last, &[1, 2]);
469475 /// }
476+ ///
477+ /// assert_eq!(None, x.split_last_chunk::<4>());
470478 /// ```
471479 #[ unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
472480 #[ rustc_const_unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
@@ -502,6 +510,8 @@ impl<T> [T] {
502510 /// elements[0] = 5;
503511 /// }
504512 /// assert_eq!(x, &[5, 3, 4]);
513+ ///
514+ /// assert_eq!(None, x.split_last_chunk_mut::<4>());
505515 /// ```
506516 #[ unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
507517 #[ rustc_const_unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
@@ -573,6 +583,8 @@ impl<T> [T] {
573583 /// last[1] = 20;
574584 /// }
575585 /// assert_eq!(x, &[0, 10, 20]);
586+ ///
587+ /// assert_eq!(None, x.last_chunk_mut::<4>());
576588 /// ```
577589 #[ unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
578590 #[ rustc_const_unstable( feature = "slice_first_last_chunk" , issue = "111774" ) ]
@@ -2035,164 +2047,6 @@ impl<T> [T] {
20352047 }
20362048 }
20372049
2038- /// Divides one slice into an array and a remainder slice at an index.
2039- ///
2040- /// The array will contain all indices from `[0, N)` (excluding
2041- /// the index `N` itself) and the slice will contain all
2042- /// indices from `[N, len)` (excluding the index `len` itself).
2043- ///
2044- /// # Panics
2045- ///
2046- /// Panics if `N > len`.
2047- ///
2048- /// # Examples
2049- ///
2050- /// ```
2051- /// #![feature(split_array)]
2052- ///
2053- /// let v = &[1, 2, 3, 4, 5, 6][..];
2054- ///
2055- /// {
2056- /// let (left, right) = v.split_array_ref::<0>();
2057- /// assert_eq!(left, &[]);
2058- /// assert_eq!(right, [1, 2, 3, 4, 5, 6]);
2059- /// }
2060- ///
2061- /// {
2062- /// let (left, right) = v.split_array_ref::<2>();
2063- /// assert_eq!(left, &[1, 2]);
2064- /// assert_eq!(right, [3, 4, 5, 6]);
2065- /// }
2066- ///
2067- /// {
2068- /// let (left, right) = v.split_array_ref::<6>();
2069- /// assert_eq!(left, &[1, 2, 3, 4, 5, 6]);
2070- /// assert_eq!(right, []);
2071- /// }
2072- /// ```
2073- #[ unstable( feature = "split_array" , reason = "new API" , issue = "90091" ) ]
2074- #[ inline]
2075- #[ track_caller]
2076- #[ must_use]
2077- pub fn split_array_ref < const N : usize > ( & self ) -> ( & [ T ; N ] , & [ T ] ) {
2078- let ( a, b) = self . split_at ( N ) ;
2079- // SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at)
2080- unsafe { ( & * ( a. as_ptr ( ) as * const [ T ; N ] ) , b) }
2081- }
2082-
2083- /// Divides one mutable slice into an array and a remainder slice at an index.
2084- ///
2085- /// The array will contain all indices from `[0, N)` (excluding
2086- /// the index `N` itself) and the slice will contain all
2087- /// indices from `[N, len)` (excluding the index `len` itself).
2088- ///
2089- /// # Panics
2090- ///
2091- /// Panics if `N > len`.
2092- ///
2093- /// # Examples
2094- ///
2095- /// ```
2096- /// #![feature(split_array)]
2097- ///
2098- /// let mut v = &mut [1, 0, 3, 0, 5, 6][..];
2099- /// let (left, right) = v.split_array_mut::<2>();
2100- /// assert_eq!(left, &mut [1, 0]);
2101- /// assert_eq!(right, [3, 0, 5, 6]);
2102- /// left[1] = 2;
2103- /// right[1] = 4;
2104- /// assert_eq!(v, [1, 2, 3, 4, 5, 6]);
2105- /// ```
2106- #[ unstable( feature = "split_array" , reason = "new API" , issue = "90091" ) ]
2107- #[ inline]
2108- #[ track_caller]
2109- #[ must_use]
2110- pub fn split_array_mut < const N : usize > ( & mut self ) -> ( & mut [ T ; N ] , & mut [ T ] ) {
2111- let ( a, b) = self . split_at_mut ( N ) ;
2112- // SAFETY: a points to [T; N]? Yes it's [T] of length N (checked by split_at_mut)
2113- unsafe { ( & mut * ( a. as_mut_ptr ( ) as * mut [ T ; N ] ) , b) }
2114- }
2115-
2116- /// Divides one slice into an array and a remainder slice at an index from
2117- /// the end.
2118- ///
2119- /// The slice will contain all indices from `[0, len - N)` (excluding
2120- /// the index `len - N` itself) and the array will contain all
2121- /// indices from `[len - N, len)` (excluding the index `len` itself).
2122- ///
2123- /// # Panics
2124- ///
2125- /// Panics if `N > len`.
2126- ///
2127- /// # Examples
2128- ///
2129- /// ```
2130- /// #![feature(split_array)]
2131- ///
2132- /// let v = &[1, 2, 3, 4, 5, 6][..];
2133- ///
2134- /// {
2135- /// let (left, right) = v.rsplit_array_ref::<0>();
2136- /// assert_eq!(left, [1, 2, 3, 4, 5, 6]);
2137- /// assert_eq!(right, &[]);
2138- /// }
2139- ///
2140- /// {
2141- /// let (left, right) = v.rsplit_array_ref::<2>();
2142- /// assert_eq!(left, [1, 2, 3, 4]);
2143- /// assert_eq!(right, &[5, 6]);
2144- /// }
2145- ///
2146- /// {
2147- /// let (left, right) = v.rsplit_array_ref::<6>();
2148- /// assert_eq!(left, []);
2149- /// assert_eq!(right, &[1, 2, 3, 4, 5, 6]);
2150- /// }
2151- /// ```
2152- #[ unstable( feature = "split_array" , reason = "new API" , issue = "90091" ) ]
2153- #[ inline]
2154- #[ must_use]
2155- pub fn rsplit_array_ref < const N : usize > ( & self ) -> ( & [ T ] , & [ T ; N ] ) {
2156- assert ! ( N <= self . len( ) ) ;
2157- let ( a, b) = self . split_at ( self . len ( ) - N ) ;
2158- // SAFETY: b points to [T; N]? Yes it's [T] of length N (checked by split_at)
2159- unsafe { ( a, & * ( b. as_ptr ( ) as * const [ T ; N ] ) ) }
2160- }
2161-
2162- /// Divides one mutable slice into an array and a remainder slice at an
2163- /// index from the end.
2164- ///
2165- /// The slice will contain all indices from `[0, len - N)` (excluding
2166- /// the index `N` itself) and the array will contain all
2167- /// indices from `[len - N, len)` (excluding the index `len` itself).
2168- ///
2169- /// # Panics
2170- ///
2171- /// Panics if `N > len`.
2172- ///
2173- /// # Examples
2174- ///
2175- /// ```
2176- /// #![feature(split_array)]
2177- ///
2178- /// let mut v = &mut [1, 0, 3, 0, 5, 6][..];
2179- /// let (left, right) = v.rsplit_array_mut::<4>();
2180- /// assert_eq!(left, [1, 0]);
2181- /// assert_eq!(right, &mut [3, 0, 5, 6]);
2182- /// left[1] = 2;
2183- /// right[1] = 4;
2184- /// assert_eq!(v, [1, 2, 3, 4, 5, 6]);
2185- /// ```
2186- #[ unstable( feature = "split_array" , reason = "new API" , issue = "90091" ) ]
2187- #[ inline]
2188- #[ must_use]
2189- pub fn rsplit_array_mut < const N : usize > ( & mut self ) -> ( & mut [ T ] , & mut [ T ; N ] ) {
2190- assert ! ( N <= self . len( ) ) ;
2191- let ( a, b) = self . split_at_mut ( self . len ( ) - N ) ;
2192- // SAFETY: b points to [T; N]? Yes it's [T] of length N (checked by split_at_mut)
2193- unsafe { ( a, & mut * ( b. as_mut_ptr ( ) as * mut [ T ; N ] ) ) }
2194- }
2195-
21962050 /// Returns an iterator over subslices separated by elements that match
21972051 /// `pred`. The matched element is not contained in the subslices.
21982052 ///
0 commit comments