std-method
Vec::into_boxed_slice
Consume a vector and produce an owned fixed-length boxed slice. Excess capacity is discarded; the operation may reallocate. Expected stdout (not executed): 3 [1, 2, 3] Common mistake: Expecting to continue pushing elements into the boxed slice.
Formal Syntax & Structure
rust syntaxrust
vector.into_boxed_slice()Working Example
Example Snippetrust
fn main() { let mut data = Vec::with_capacity(10); data.extend([1, 2, 3]); let boxed = data.into_boxed_slice(); println!("{} {boxed:?}", boxed.len());}