| 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | |
| 3 | //! Additional (and temporary) slice helpers. |
| 4 | |
| 5 | /// Extension trait providing a portable version of [`as_flattened`] and |
| 6 | /// [`as_flattened_mut`]. |
| 7 | /// |
| 8 | /// In Rust 1.80, the previously unstable `slice::flatten` family of methods |
| 9 | /// have been stabilized and renamed from `flatten` to `as_flattened`. |
| 10 | /// |
| 11 | /// This creates an issue for as long as the MSRV is < 1.80, as the same functionality is provided |
| 12 | /// by different methods depending on the compiler version. |
| 13 | /// |
| 14 | /// This extension trait solves this by abstracting `as_flatten` and calling the correct method |
| 15 | /// depending on the Rust version. |
| 16 | /// |
| 17 | /// This trait can be removed once the MSRV passes 1.80. |
| 18 | /// |
| 19 | /// [`as_flattened`]: https://doc.rust-lang.org/std/primitive.slice.html#method.as_flattened |
| 20 | /// [`as_flattened_mut`]: https://doc.rust-lang.org/std/primitive.slice.html#method.as_flattened_mut |
| 21 | |
| 22 | |
| 23 | /// Takes a `&[[T; N]]` and flattens it to a `&[T]`. |
| 24 | /// |
| 25 | /// This is an portable layer on top of [`as_flattened`]; see its documentation for details. |
| 26 | /// |
| 27 | /// [`as_flattened`]: https://doc.rust-lang.org/std/primitive.slice.html#method.as_flattened |
| 28 | ; |
| 29 | |
| 30 | /// Takes a `&mut [[T; N]]` and flattens it to a `&mut [T]`. |
| 31 | /// |
| 32 | /// This is an portable layer on top of [`as_flattened_mut`]; see its documentation for details. |
| 33 | /// |
| 34 | /// [`as_flattened_mut`]: https://doc.rust-lang.org/std/primitive.slice.html#method.as_flattened_mut |
| 35 | ; |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | self.flatten |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | self.flatten_mut |
| 48 | |
| 49 |