Skip to content
This repository was archived by the owner on Oct 9, 2018. It is now read-only.

Clarify where imports should be placed #27

Open
ftxqxd opened this issue Aug 1, 2014 · 1 comment
Open

Clarify where imports should be placed #27

ftxqxd opened this issue Aug 1, 2014 · 1 comment

Comments

@ftxqxd
Copy link

ftxqxd commented Aug 1, 2014

In most code, use imports are placed directly at the top of the file/module. However, sometimes I see them situated within a function. The Rust guidelines would be a great place to clarify where use imports should be placed. My recommendation would be to put all imports at the top of the module, except maybe for tests, where any imports specific to that function should be placed within that function only. (For example, if only one test uses std::collections::HashMap, the use statement should be placed within that function only.) Oh, and maybe main should also have any specific imports at the top of the function rather than the module.

@lilyball
Copy link
Contributor

lilyball commented Aug 1, 2014

use imports that are expected to only ever used within a single function are reasonable candidates to put in the function. It's a judgement call.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants