Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the prelude?

Tags:

rust

When talking about imports, the word prelude is used every so often by the rustaceans.

What is this prelude they talk about?

How does it affect my Rust programs?

like image 865
Matthieu M. Avatar asked Apr 03 '16 11:04

Matthieu M.


People also ask

What is the meaning behind The Prelude?

' The goal of the poem is to demonstrate his fitness to produce great poetry, and The Prelude itself becomes evidence of that fitness." It traces the growth of the poet's mind by stressing the mutual consciousness and spiritual communion between the world of nature and man.

What is the story of The Prelude?

The Prelude is a long autobiographical poem in which William Wordsworth depicts his own spiritual and poetic development. In this excerpt, Wordsworth recounts an episode from his childhood, when he stole a small boat and rowed into the middle of a lake at night.

What kind of poem is The Prelude?

The Prelude, in full The Prelude, or Growth of a Poet's Mind, autobiographical epic poem in blank verse by William Wordsworth, published posthumously in 1850. Originally planned as an introduction to another work, the poem is organized into 14 sections, or books.

What is the poets message in The Prelude?

The ​poet's aim was to write a three part autobiographical epic​called “The Recluse”, with The Prelude being the first volume of 400 pages. He wanted to present ideas from his past then explore their philosophical significance through the medium of nature and society, but sadly died before its completion. of the world.


1 Answers

In Rust, in order to use a symbol, you must either:

  • have defined the symbol in the current scope
  • have imported the symbol in the current scope via a use directive: use std::mem;
  • be referring to the symbol using its absolute path: std::mem::replace

however, some very few symbols can be used without such actions: Option or Copy for example!

This is due to the Rust prelude.

A number of traits, types and functions were judged to be so frequently used that it made sense not to require that their use required explicitly importing the necessary symbols each and every time. This is achieved thanks to two implicit actions taken by the compiler:

  • at the root of every crate, the compiler injects an implicit extern crate std;
  • in every module, the compiler injects an implicit use std::prelude::v1::*; (for now)

std::prelude::v1 is just a regular module which re-exports those frequently used symbols using the pub use ... syntax. Its exact content can be found here.


A number of other libraries, or even sub-components of the standard library also define a prelude module that you may import with the same glob import syntax: use xxx::prelude::*;. Unlike the std::prelude however those are not special-cased by the compiler and therefore require explicit importing.


The compiler is agnostic to the exact content of the prelude, therefore if one was to replace the std crate with their own (for example, in embedded development) then one would decide what goes into their std::prelude::v1 module.

like image 173
Matthieu M. Avatar answered Nov 09 '22 17:11

Matthieu M.