Does use statement increase compile time?

Hello!

I'm new to rust and I'm trying to do some projects to learn language better. A lot of libraries on crates.io use use library::prelude::* statements. My question is, do I pay compile time cost for importing entire prelude, or just for parts I use in code? Should I import stuff I am using in this file, or should I import entire prelude? In C languages, importing *.h file is attaching header to compile unit, but I can't find info how does it work in Rust.

No it doesn't increase compile times to import the entire prelude. But it's generally more clear to list off exactly what you are using.

In Rust crates, not files, are the units of compilation.

3 Likes

It's also more robust. Exporting new symbols isn't considered a breaking change for a crate. If those new symbols are the same as ones you're already using from somewhere else, it could cause some minor problems that need to be fixed.

3 Likes

Note: this can only happen if you use multiple glob imports in the same module, otherwise there isn't a forward compatibility problem.

1 Like

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.