I am currently learning about modules and crates in Rust and I thought I could learn best by looking at a real and very commonly used module: std::collections
. I want to be able to view the actual files of this package. However, I can't find it on my computer. I have looked in the folder where I created my project (and all subfolders), as well as in the C:/users/(username)/.cargo
folder. I am running an x64 Windows 10 PC. Please let me know where I can find the std::collections
module on my system. Thank you!
Asked
Active
Viewed 190 times
1
-
Protip: VoidTools.com/Everything – Dai Jun 16 '21 at 02:30
-
Your best bet is probably to look at the [source](https://github.com/rust-lang/rust/tree/master/library/std/src/collections) on github, or clone the compiler repo – transistor Jun 16 '21 at 02:37
-
1Std is shipped out prebuilt because it takes the nightly compiler plus a long time to build. You won't find the source code unless you put it there. – Aiden4 Jun 16 '21 at 03:12
-
@Dai Hmm that link did not work. – Arya n Jun 16 '21 at 04:14
-
@transitor Thank you very much that is what I'm looking for! – Arya n Jun 16 '21 at 04:14
1 Answers
1
The default location for components retrieved via rustup
are in $HOME/.rustup/
which are organized by toolchain. The source is part of the rust-src
component and may need to be installed manually via rustup component add rust-src
. The std
crate can then be found in lib/rustlib/src/rust/library/std
.
So the full path for the std::collections
module on Windows should be:
C:\Users\<USER>\.rustup\toolchains\<TOOLCHAIN>\lib\rustlib\src\rust\library\std\src\collections
See also: Where is the source code of Rust target components?

kmdreko
- 42,554
- 6
- 57
- 106
-
Note that it will only be there if you install the `rust-src` component (`rustup component add rust-src`) – Jmb Jun 16 '21 at 06:34
-
@Jmb I've added that as part of the answer. I think I always forget that because rust-analyzer [installs it automatically](https://rust-analyzer.github.io/manual.html#installation). – kmdreko Jun 16 '21 at 06:41