ownership
Rust Boxed slices
A boxed slice owns a dynamically sized sequence. Its length is available through the pointer metadata, and unlike Vec it has no push operation. Use it when the owned collection should have a fixed length. Expected output (not executed): [12, 15, 16] Why: The elements remain mutable through the unique box even though the length is fixed. Common mistake: Confusing a fixed length with immutable elements.
Formal Syntax & Structure
rust syntaxrust
let data: Box<[T]> = vec.into_boxed_slice();Working Example
Example Snippetrust
fn main() { let mut readings = vec![12, 14, 16].into_boxed_slice(); readings[1] = 15; println!("{:?}", readings);}