Skip to content

Latest commit

 

History

History
42 lines (31 loc) · 1.65 KB

functions-that-end-with-exclamation-mark.md

File metadata and controls

42 lines (31 loc) · 1.65 KB
title timestamp author published description tags todo
Functions that end with an exclamation mark in Rust !
2023-11-30 01:30:01 -0800
szabgab
true
There are a number of function-like calls in Rust that end by an exclamation mark. What are those?
exclamation mark
!
macro
Examples writing macros

As you read Rust code you will see many function calls that have an exclamation mark ! at the end.

Some of the most common ones are:

In reality, these are called macros. They are replaced by more Rust code at compile time.

There are a number of macros in the standard library and there are many crates sharing additional macros.

Macros can be useful to eliminate duplicate code that for some reason we cannot, or do not want to put in a function.

They can also include Rust code that would be executed during the compilation of the code.