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

Unstable Rust feature "frontmatter"

Frontmatter

Frontmatter is an optional section for content intended for external tools without requiring these tools to have full knowledge of the Rust grammar.

#!/usr/bin/env cargo
---
[dependencies]
fastrand = "2"
---

fn main() {
    let num = fastrand::i32(..);
    println!("{num}");
}

Frontmatter may only be preceded by a shebang and whitespace.

The delimiters are referred to as a fence. The opening and closing fences must be at the start of a line. They must be a matching pair of three or more hyphens (-). A fence may be followed by horizontal whitespace.

Following the opening fence may be an infostring for identifying the intention of the contained content. An infostring may be followed by horizontal whitespace.

The body of the frontmatter may contain any content except for a line starting with as many or more hyphens (-) than in the fences.


  1. The closing fence must have the same number of - as the opening fence