liveBook · Manning

Print

As explained in Learn Rust in a Month of Lunches

Printing is the operation of writing textual or formatted data to an output stream.

Rust printing writes text or formatted values to an output stream. The basic tools are the print! and println! macros: print! leaves output on the current line, while println! adds a newline. section 1.0 section 2.10

Begin with a small string, then add formatting when the output needs values, alignment, escapes, or another representation. Rust’s compiler checks the formatting choices before the program runs. section 1.0 section 2.10

Printing can handle several common output tasks:

  • Insert values with positional arguments such as {0}, named arguments such as {city1}, or ordinary placeholders such as {}. section 2.10
  • Represent values with Display, Debug, pretty Debug, binary, hexadecimal, or octal formatting. section 2.10
  • Control layout with padding, alignment, minimum widths, maximum widths, and fill characters. section 2.10
  • Print multiline text, escaped characters, raw strings, ASCII bytes, Unicode characters, and pointer addresses. section 2.10

Formatting a small report

fn main() { let title = "TODAY'S NEWS"; println!("{:-^30}", title); let a = "SEOUL"; let b = "TOKYO"; println!("{city1:-<15}{city2:->15}", city1 = a, city2 = b); } The first line centers the title with hyphens; the second aligns two named values in fixed-width fields. section 2.10

fn main() {                                                #1
    print!("\t Start with a tab\nand move to a new line");
}

Compare the compact print! example with its visible tab and newline output to see how escape sequences affect layout. section 2.10

How Learn Rust in a Month of Lunches covers it

How deep it goes
Explains runnable syntax, formatting forms, escapes, raw strings, bytes, Unicode, pointers, and layout controls without deeper internals.
Examples
Uses tabs, multiline strings, escaped paths, raw strings, byte output, Unicode escapes, pointer addresses, and aligned news-style text.
What it assumes
Builds from zero with basic types, variables, code blocks, and type inference while expecting no advanced printing knowledge.
What you can do after
Apply it via Rust’s print! and println! macros to produce readable text and formatted program output.
How it connects
Connects printing with string literals, escape sequences, raw strings, Unicode, byte strings, pointers, and format specifiers.

Also explained in

Compare how 5 books explain print →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Rust in a Month of Lunches. The section links point to the parts of the book it draws on.