trait

ToString — convert displayable values into text

Create an owned text representation of a value. Types implementing Display receive ToString automatically. Expected stdout (not executed): 42 42 Common mistake: Assuming the text representation is a guaranteed lossless serialization.

Formal Syntax & Structure

rust syntaxrust
fn to_string(&self) -> String

Working Example

Example Snippetrust
fn main() {    let count = 42;    let text = count.to_string();    println!("{text} {count}");}
Rust Reference