# Custom prelude imports

**URL:** <https://internals.rust-lang.org/t/custom-prelude-imports/14147>\
**Category:** language design\
**Created:** [March 1, 2021, 3:09am UTC](https://internals.rust-lang.org/t/custom-prelude-imports/14147 "2021-03-01T03:09:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibraheemdev](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ibraheemdev/32/13406_2.png) [@ibraheemdev](https://internals.rust-lang.org/u/ibraheemdev)\
**Post date:** [March 1, 2021, 3:09am UTC](https://internals.rust-lang.org/t/custom-prelude-imports/14147/1 "2021-03-01T03:09:06Z")

</div>

There are many times where it would be useful to have crate-wide prelude imports. Rust already has `prelude_import` for `std::prelude`, so why not let users use it also?

```rust
#[prelude_import]
use bar::baz;

mod foo {
    use baz::Foo;
}

```

The motivation for this is pretty clear, but there are a couple specific use cases that I want to highlight:

- "Add" to `std::prelude` - there have been long arguments about adding items like `std::mem` or `std::mem::{replace, swap}` to std's prelude, and allowing custom preludes would let users choose whatever they want.
- Extension traits. Some libraries, such as `futures` for example, have extension traits that are indispensable (`StreamExt`, `FuturesExt`). These crates already have a `prelude` module to address this, but many crates must [copy paste the import throughout their code](https://github.com/libp2p/rust-libp2p/search?q=use+futures%3A%3Aprelude%3A%3A*) and custom preludes would make this more ergonomic.
- `use crate::prelude::*` is already a common practice, so letting users propagate it throughout their crate makes a lot of sense.
- Make the `std::prelude` import less "magical".
- Domain specific applications will use specific items from external crates over and over again throughout their entire crate. Prelude imports make this more ergonomic.

Potential downsides:

- Some people are already against glob prelude imports, and this feature makes them a first class citizen. However, prelude imports are sometimes need, and I think this feature could be very beneficial.
- Makes imports harder to follow for someone reading the code.
- Prelude shadowing might cause issues?

Previous work: [RFC 80](https://github.com/rust-lang/rfcs/pull/890)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [May 30, 2021, 3:09am UTC](https://internals.rust-lang.org/t/custom-prelude-imports/14147/2 "2021-05-30T03:09:07Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
