std-function

Rust Box::new

This constructor accepts an owned value. For a non-Copy input the original binding is moved; the new box controls its lifetime. Normal allocation failure is not returned as Result by this API. Expected output (not executed): 7 Why: The String header is now owned by the box; the existing String buffer is not deep-cloned. Common mistake: Trying to use label after passing it into Box::new.

Formal Syntax & Structure

rust syntaxrust
Box::new(value: T) -> Box<T>

Working Example

Example Snippetrust
fn main() {    let label = String::from("receipt");    let stored = Box::new(label);    println!("{}", stored.len());}
Rust Reference