Movatterモバイル変換


[0]ホーム

URL:


format

std

Macroformat 

1.0.0 ·Source
macro_rules! format {    ($($arg:tt)*) => { ... };}
Expand description

Creates aString using interpolation of runtime expressions.

The first argumentformat! receives is a format string. This must be a stringliteral. The power of the formatting string is in the{}s contained.Additional parameters passed toformat! replace the{}s within theformatting string in the order given unless named or positional parametersare used.

Seethe formatting syntax documentation instd::fmtfor details.

A common use forformat! is concatenation and interpolation of strings.The same convention is used withprint! andwrite! macros,depending on the intended destination of the string; all these macros internally useformat_args!.

To convert a single value to a string, use theto_string method. Thiswill use theDisplay formatting trait.

To concatenate literals into a&'static str, use theconcat! macro.

§Panics

format! panics if a formatting trait implementation returns an error.This indicates an incorrect implementationsincefmt::Write for String never returns an error itself.

§Examples

format!("test");// => "test"format!("hello {}","world!");// => "hello world!"format!("x = {}, y = {val}",10, val =30);// => "x = 10, y = 30"let(x, y) = (1,2);format!("{x} + {y} = 3");// => "1 + 2 = 3"

[8]ページ先頭

©2009-2026 Movatter.jp