On this page
  1. format
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

format

Prev: `Error` | Up: error_and_fmt | Next: ffi
Rel: error_and_fmt, rust/builtins
Ref: Rust std — format
Tags: #public #prog #rust #stdlib #error_and_fmt #tier/core


Signature & Overview

format!("user={name}, count={count}")

Macro returning a newly allocated String with compile-time checked format arguments.

Notes & Pitfalls

Example

fn main() {
    let name = "Ada";
    let score = 98.5;
    let s = format!("{name} scored {score:.1}%");
    assert_eq!(s, "Ada scored 98.5%");
}

Linked from

Related notes