// plain
Reversing a Rust slice can be done using the reverse()
method. This method is part of the std::slice
module.
let mut my_slice = [1, 2, 3, 4];
my_slice.reverse();
[4, 3, 2, 1]
let mut my_slice = [1, 2, 3, 4];
: This line declares a mutable slicemy_slice
with elements1
,2
,3
, and4
.my_slice.reverse();
: This line calls thereverse()
method on themy_slice
slice, which reverses the order of the elements in the slice.
group: rust-slice