std-method

slice::reverse

Reverse the current order in place, without comparing elements. It is not a descending sort unless the input was already ascending. Expected stdout (not executed): ["shop", "park", "home"] Common mistake: Using reverse as a substitute for sorting arbitrary values.

Formal Syntax & Structure

rust syntaxrust
slice.reverse()

Working Example

Example Snippetrust
fn main() {    let mut route = ["home", "park", "shop"];    route.reverse();    println!("{route:?}");}
Rust Reference