How to see the code for crate published in Crate.io


#1

I run into different crates specifying different versions of same library and then causing build failures. Of-course carefully planning Cargo.toml etc will avoid it, but I’m just trying to find out if these two things are possible:

<1> For any code published to the crates, can i see the source code from within the crate (github repository link is what we write in Cargo.toml so can be invalid as well) - so is there any inherent way to check the source code from what is there in crates.io itself ?

<2> cargo build first downloads the source and then compiles it if there is anything in Cargo.toml as [dependencies] from crates.io. I am on linux. So is there anyway i can browse this downloaded source code ?


#2

Sure:

[andrew@Serval crates.io] curl -L 'https://crates.io/api/v1/crates/regex/0.1.38/download' | tar -zxf -
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 82065  100 82065    0     0   107k      0 --:--:-- --:--:-- --:--:--  202k
[andrew@Serval crates.io] cd regex-0.1.38/
[andrew@Serval regex-0.1.38] $EDITOR src/lib.rs

I don’t know what the exact directory layout is, but tree $HOME/.cargo | less should be enough to make you dangerous. :slight_smile: