Help us understand prelude usage

Some recent discussion on the Ratatui crate evoked a bit of push back on the use of a prelude module with glob imports. A (real) example of this from our BarChart example code is:

use ratatui::{
    backend::Backend,
    buffer::Buffer,
    layout::{Constraint, Direction, Layout, Rect},
    style::{Color, Modifier, Style, Stylize},
    text::Line,
    widgets::{Bar, BarChart, BarGroup, Block, Borders, Paragraph, Widget},
    Terminal,
};

compared to:

use ratatui::{
    prelude::*,
    widgets::{Bar, BarChart, BarGroup, Block, Borders, Paragraph},
};

We understand that people consume code in many different ways, e.g. you may be reading the source code of the library in GitHub or your editor to understand how an implementation works, or you may be reading reference docs / examples on a website. We want to understand these scenarios more generally and work out whether we need some project guidelines on when and when not to use preludes.

I’d like to get a feel for how the following scenarios are perceived generally (by both new users as well as more experienced rust users):

The downsides of using preludes / glob imports are (not an exhaustive list):

  • when reading code (especially without aa LSP), there’s no easy way to know where a type comes from due to the glob imports
  • when importing a prelude from external code you open yourself up to naming clashes
  • using a prelude lessens the ability to reason about module hierarchy concerns

The upsides are:

  • traits that only provide methods to other types don’t appear in the rest of the file
  • reduced code verbosity when writing rustdoc examples
  • reduced verbosity when writing example apps (as every app needs Terminal, Backend, Line, Span, Text, Layout, Style, etc.)
  • reduction of import arrangement issues in PRs etc.
  • reduction of boilerplate code internal to the library
  • makes tutorial style code easier to write (as the import statements tend to clutter)
  • prelude is an opt-in thing for library consumers

(the verbosity arguments are less about typing, but more about concise communication)

My questions for the wisdom of the Ratatui users:

  1. How do you feel about preludes generally?
  2. How do you feel about reading preludes in rustdoc examples at each level (module / type / function)?
  3. How do you feel about reading preludes in example code in a repo?
  4. How do you feel about reading preludes in tutorial / concept code on websites / blogs etc?
  5. How do you feel about using preludes when maintaining a library?
  6. How do you feel about using preludes when writing your own application?
  7. Have I missed any upsides / downsides?
  8. Do you have any concrete examples where you’ve experienced the upsides or downsides to library preludes.

(This was previously cross posted in the Rust User’s forum at To `use prelude::*` or to not to `use prelude::*` - that is the question - help - The Rust Programming Language Forum and on reddit at https://www.reddit.com/r/rust/comments/1cle18j/to_prelude_or_to_not_to_prelude/)