Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

The print macros are used to print on console, either on standard output (a.k.a.: stdout) or standard error (a.k.a.: stderr). The ones terminating with the suffix ln add a line feed character at the end of the printed string. See Table 1 for a sum-up of those macros.

Table 1:Print macros

Macro

Stream

Line feed

print!()

stdout

No

println!()

stdout

Yes

eprint!()

stderr

No

eprintln!()

stderr

Yes

All macros take a literal string as first argument, then zero or more values that are used to replace format string markers {}.

9.1.1Printing of simple objects

Printing a simple string:

Hello, world!

Using unnamed markers:

my values: 12.34 789

Using named markers:

my_values: 789 - 12.34

Printing a variable:

my_var: 123

Insert leading characters:

my_var: 00123

Setting precision on a float:

x: 0.12346

Using a variable for precision:

mismatched types

9.1.2Printing of complex objects

Printing a complex object requires a special formatter. The easiest way is to use the Debug formatter that is included in core objects and objects from the standard library. For custom types, the Debug trait can easily be implemented using the derive() attribute as we will see later.

Let us define a tuple object with three values:

The Debug formatter being implemented for tuple objects, we can use the special debug formatter operator ? to print our tuple:

Using the # option, we can also enable the pretty-print output: