1

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!

Cryptjar
  • 1,079
  • 8
  • 13
Arya n
  • 13
  • 5

1 Answers1

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