Cargo invoice has failed: error: exit code: 101

Rust language
When you edit the Rust “Thebook” second chapter “guess” game Code in VS Code, try adding a rand dependency in cargo. Toml, which is

cargo.toml

[dependencies]
rand = "0.7.3"

after typing $cargo build on the command line,

is found

Cargo invocation has failed: Error: exit code: 101.

such a popup reminder, prompt crate enable failure.

OUTPUT window prompts as follows:

Running `cargo build --bin=instances --package=instances
--message-format=json`...
    Blocking waiting for file lock on package cache
    Updating crates.io index warning: spurious network error (2 tries remaining): failed to send request: 操作超时 ; class=Os (2) 
    warning: spurious network error (1 tries remaining): failed to send request: 操作超时 ; class=Os (2) 
    error: failed to get `rand` as a dependency of package `instances v1.46.0 (D:\DataFiles\CodesLearning\RUST\Instances)`

Caused by:   failed to load source for dependency `rand`

Caused by:   Unable to update registry `https://github.com/rust-lang/crates.io-index`

Caused by:   failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:   failed to send request: 操作超时  ; class=Os (2)

it turned out that the connection to Github was timed out. This problem will also be pop-ups for installed updates that are ignored when checking the rust-Analyzer plug-in version every time VS Code is started.

below provides the method to connect to Github. This method also applies to the problem of not being able to connect to Github when a web page is logged on. IP addresses are usually added to the HOSTS file.
host files in C:// Windows/system32/dreivrs/etc directory. You can right click -> Property changes the write permission of User before editing and saving.
can be learned that the current lot by https://github.com.ipaddress.com/www.github.com website IP address has been changed, so a lot of articles referred to in the hosts change have failed. The code added to the hosts file is provided as follows:

#Github
140.82.113.4 github.com 

of course, it is more recommended to use the above link to query before making changes, to prevent IP address update invalid. Finally, don’t forget to save the file hosts, , and unwrite User .

Read More: