std-method

VecDeque::make_contiguous

Rearrange ring-buffer storage so its logical order occupies a single mutable slice. No allocation is required by this method. The returned slice can be sorted in place, changing the queue order accordingly. Expected stdout (not executed): [1, 2, 3] Common mistake: Calling it merely to read the queue in logical order; iter already does that without rearrangement.

Formal Syntax & Structure

rust syntaxrust
pub fn make_contiguous(&mut self) -> &mut [T]

Working Example

Example Snippetrust
fn main() {    use std::collections::VecDeque;    let mut q = VecDeque::from([3, 1, 2]);    q.make_contiguous().sort();    println!("{q:?}");}
Rust Reference