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 function-like macros are a type of procedural macros that look like function calls. They can, however, accept an unknown number of arguments. Like the declarative macros they end with an exclamation mark (!). A list of the main function-like macros is provided in Table 1.

Table 1:Most used function-like macros

Macro

Description

Example

format!()

Create a formatted String.

let tag = format!("{}_{}.{}", prefix, x.name(), get_version());

print!()

Print formatted text on standard output stream.

print!("Hello {name}! You have {} messages.", msg.count());

println!()

Same as print!(), but appends a new line character.

eprint!()

Same as print!(), but prints on the standard error stream.

eprint!("My important message");

eprintln!()

Same as eprint!(), but appends a new line character.

panic!()

Issue an unrecoverable error.

panic!("Data impossible to process.");

todo!()

Mark unfinished code section. Panic if reached.

todo!("I really need to code this.");

unimplemented!()

Mark non-implemented code section. Panic if reached.

todo!("There is no plan to implement this functionality, ever.");

unreachable!()

Mark unreachable code. Panic if reached.

unreachable!("We should never get here.");

Example with the println! macro:

Good morning.

The same macro can accept additional arguments:

Good morning, John.