Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Format Strings

Format strings are strings which include a special notation to insert expressions into a text.

test

std::debug::assert_eq(["{2 + 5}", "7"]);

Usually they are used to insert parameters into text:

test

fn print_length(length: Length) {
    std::print("{length}");
}

print_length(7mm);

Bad Expression in Format String

If a format string expression cannot be evaluated, you will get an error.

test

fn print_length(length: Length) {
    std::print("{size}"); // error: size is not known
}

print_length(7mm);