I usually sort them like this and feel like that's roughly what most people are doing:
- Imports from third-party libraries
- Imports from std
- Imports from own crate
mod
statements and respective (pub use
) imports from sub-modulespub
types & functions- private types & functions
- Unit tests
Generally, the logic is public API at the top, internals at the bottom, so that other devs using your module find everything they need at the top.
One exception to that are the imports. Aside from pub use
, those would be better placed at the bottom. We just seem to put them up top for reasons of We've Always Done It This Wayβ’.