std-method

String::into_boxed_str

Consume a growable String and produce an owned boxed string slice. Excess capacity may be discarded. Expected stdout (not executed): label Common mistake: Expecting the consumed String to remain usable.

Formal Syntax & Structure

rust syntaxrust
fn into_boxed_str(self) -> Box<str>

Working Example

Example Snippetrust
fn main() {    let s = String::from("label");    let boxed: Box<str> = s.into_boxed_str();    println!("{boxed}");}
Rust Reference