The following is the explanation of
The Rust Preclude in rust std doc.
The prelude is the list of things that Rust automatically imports into every Rust program.
Apparently, it is not the literal meaning of 'preclude'. So my question is:
Why does rust use 'preclude' to do so?
I believe you've misread the sentence. Whereas "preclude" is defined as
prevent from happening; make impossible.
The word here used is "prelude", with no "c". English defines it as:
an action or event serving as an introduction to something more important.
As in, something which happens before the main event. Rust doesn't uses it in exactly this way, but it is slightly similar.
In Rust, a prelude for a library or module is a list of things which are useful for most usages of that program or module, but aren't necessarily the thing you directly interact with.
std::prelude is a group of utilities or things useful when writing most rust programs which interact with std. For instance,
Result aren't the main thing you're trying to do, but almost everything uses them.
As for "why", I'm not entirely sure. I believe there's some precedent in other programming languages, but I'm not remembering any off the top of my head. The usage is not exactly the same as English, but it is similar. You could say things from the rust prelude are imported and used as a prelude to the main event, other functions/items for specific functionality. This analogy is a stretch, but I think it's why the word was used? Maybe someone else has more knowledge of the history here.
As another example,
std::io::prelude is a group of things that are useful when interacting with
std::io a lot. For instance, it includes the
Write traits (so you can use methods from those traits on structs implementing them). It's intended to be used with
use std::io::prelude::*;. Many crates also define
prelude modules for a similar purpose: utilities which (usually) aren't the main point of the library, but are useful for interacting with those main utilities.
The term may have been borrowed from Haskell:
Thank you. I did misread the sentence. Embarrassed...
Thank you. I mistook "prelude" for "preclude". Nuts!
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.