Prelude

From Rust Community Wiki
Revision as of 01:26, 4 August 2020 by Aloso (talk | contribs) (Use better templates)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

A prelude is a module that is intended for importing all items in it, using a glob import (*). For example:

use std::io::prelude::*;

This makes all items in the prelude available.

The Rust prelude[edit | edit source]

The standard library has a special prelude, which is imported automatically in every Rust file. It is located in std::preludeThis links to official Rust documentation and contains the following items:

In #![no_std] crates, the core prelude is used instead, which is a subset of the prelude in std. There is also an experimental alloc prelude to complement the core prelude. This one is not imported automatically, however.

Note that primitive types are always in scope, so they don't need to be imported.

Other preludes[edit | edit source]

Any crate can define a prelude. However, these preludes must be imported manually. For example, the standard library contains the following preludes, besides the ones already mentioned: