Rollup merge of #105858 - scottmcm:extra-as-chunks-example, r=the8472

Another `as_chunks` example

I really liked this structure that dtolney brought up in #105316, so wanted to put it in the docs to help others use it.
This commit is contained in:
Matthias Krüger 2022-12-18 18:57:04 +01:00 committed by GitHub
commit 63fdc9a857
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1002,6 +1002,17 @@ pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> {
/// assert_eq!(chunks, &[['l', 'o'], ['r', 'e']]);
/// assert_eq!(remainder, &['m']);
/// ```
///
/// If you expect the slice to be an exact multiple, you can combine
/// `let`-`else` with an empty slice pattern:
/// ```
/// #![feature(slice_as_chunks)]
/// let slice = ['R', 'u', 's', 't'];
/// let (chunks, []) = slice.as_chunks::<2>() else {
/// panic!("slice didn't have even length")
/// };
/// assert_eq!(chunks, &[['R', 'u'], ['s', 't']]);
/// ```
#[unstable(feature = "slice_as_chunks", issue = "74985")]
#[inline]
#[must_use]