std-method

String::into_bytes

Consume the owned text and return its UTF-8 bytes. The original String binding is no longer usable. Expected stdout (not executed): [216, 180] Common mistake: Expecting to keep using the moved String.

Formal Syntax & Structure

rust syntaxrust
fn into_bytes(self) -> Vec<u8>

Working Example

Example Snippetrust
fn main() {    let text = String::from("ش");    let bytes = text.into_bytes();    println!("{bytes:?}");}
Rust Reference