std-method

slice::rotate_right

Shift the last k elements to the beginning without changing length or the order within each moved section. k must not exceed len. Expected stdout (not executed): ["Wed", "Mon", "Tue"] Common mistake: Passing an amount greater than the slice length without reducing it first.

Formal Syntax & Structure

rust syntaxrust
slice.rotate_right(k)

Working Example

Example Snippetrust
fn main() {    let mut days = ["Mon", "Tue", "Wed"];    days.rotate_right(1);    println!("{days:?}");}
Rust Reference