使用vim ${HOME}/.cargo/config,然后在这个文件里边填上下边的内容:
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

使用cargo new test_rust创建一个可执行项目,使用yum install tree安装tree,tree -F .查看可执行目录下有什么。
使用vim test_rust/Cargo.toml填上以下的内容:
name = "test_rust"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.11",features = ["blocking"]}
html2md = "0.2"
使用vim test_rust/src/main.rs填上如下的内容:
use std::fs;
use std::path::PathBuf;
fn main() {
let url = "https://www.baidu.com/";
let output = "baidu.md";
println!("获取到的地址: {}", url);
let body = reqwest::blocking::get(url).unwrap().text().unwrap();
println!("正在转换中");
let md = html2md::parse_html(&body);
fs::write(output, md.as_bytes()).unwrap();
let mut config_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
config_path.push(output);
println!("md放到的位置:{:?}",config_path);
}

使用cd test_rust进入到可执行目录里边,然后执行cargo run,
发现报了许多下边的内容:
Updating `ustc` index
Downloaded aho-corasick v0.7.18 (registry `ustc`)
Downloaded foreign-types v0.3.2 (registry `ustc`)
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
Downloaded foreign-types-shared v0.1.1 (registry `ustc`)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: crates)
error: failed to download from `https://crates-io.proxy.ustclug.org/api/v1/crates/cfg-if/1.0.0/download`
Caused by:
[6] Couldn't resolve host name (Could not resolve host: crates)

解决方案参照https://mirrors.ustc.edu.cn/help/crates.io-index.html。
使用export CARGO_HTTP_MULTIPLEXING=false设置一下,然后再使用 cargo run执行。
Downloaded autocfg v1.1.0 (registry `ustc`)
Downloaded futures-task v0.3.21 (registry `ustc`)
Downloaded bytes v1.1.0 (registry `ustc`)
Downloaded lazy_static v1.4.0 (registry `ustc`)
Downloaded pin-project-lite v0.2.8 (registry `ustc`)
Downloaded rand_core v0.6.3 (registry `ustc`)
Downloaded socket2 v0.4.4 (registry `ustc`)
Downloaded unicode-normalization v0.1.19 (registry `ustc`)
Downloaded parking_lot_core v0.9.2 (registry `ustc`)
Downloaded h2 v0.3.13 (registry `ustc`)
Downloaded precomputed-hash v0.1.1 (registry `ustc`)
Downloaded proc-macro2 v1.0.37 (registry `ustc`)
Downloaded try-lock v0.2.3 (registry `ustc`)
Downloaded cfg-if v1.0.0 (registry `ustc`)
Downloaded futures-io v0.3.21 (registry `ustc`)
Downloaded regex-syntax v0.6.25 (registry `ustc`)
Downloaded httpdate v1.0.2 (registry `ustc`)
Downloaded itoa v1.0.1 (registry `ustc`)
Downloaded hyper-tls v0.5.0 (registry `ustc`)
Downloaded markup5ever_rcdom v0.1.0 (registry `ustc`)
Downloaded native-tls v0.2.10 (registry `ustc`)
Downloaded openssl-probe v0.1.5 (registry `ustc`)
Downloaded libc v0.2.122 (registry `ustc`)
Downloaded openssl v0.10.38 (registry `ustc`)
Downloaded phf_shared v0.10.0 (registry `ustc`)
Downloaded pkg-config v0.3.25 (registry `ustc`)
Downloaded siphasher v0.3.10 (registry `ustc`)
Downloaded string_cache v0.8.4 (registry `ustc`)
Downloaded tower-service v0.3.1 (registry `ustc`)
Downloaded tokio v1.17.0 (registry `ustc`)
Downloaded bitflags v1.3.2 (registry `ustc`)
Downloaded futures-channel v0.3.21 (registry `ustc`)
Downloaded tracing v0.1.33 (registry `ustc`)
Downloaded futures-util v0.3.21 (registry `ustc`)
Downloaded hashbrown v0.11.2 (registry `ustc`)
Downloaded html2md v0.2.13 (registry `ustc`)
Downloaded base64 v0.13.0 (registry `ustc`)
Downloaded log v0.4.16 (registry `ustc`)
Downloaded hyper v0.14.18 (registry `ustc`)
Downloaded markup5ever v0.10.1 (registry `ustc`)
Downloaded num_cpus v1.13.1 (registry `ustc`)
Downloaded percent-encoding v2.1.0 (registry `ustc`)
Downloaded mio v0.8.2 (registry `ustc`)
Downloaded phf_shared v0.8.0 (registry `ustc`)
Downloaded memchr v2.4.1 (registry `ustc`)
Downloaded rand v0.7.3 (registry `ustc`)
Downloaded serde_urlencoded v0.7.1 (registry `ustc`)
Downloaded reqwest v0.11.10 (registry `ustc`)
Downloaded tinyvec v1.5.1 (registry `ustc`)
Downloaded tokio-native-tls v0.3.0 (registry `ustc`)
Downloaded syn v1.0.91 (registry `ustc`)
Downloaded unicode-xid v0.2.2 (registry `ustc`)
Downloaded want v0.3.0 (registry `ustc`)
Downloaded regex v1.5.5 (registry `ustc`)
Downloaded futf v0.1.5 (registry `ustc`)
Downloaded getrandom v0.1.16 (registry `ustc`)
Downloaded http v0.2.6 (registry `ustc`)
Downloaded form_urlencoded v1.0.1 (registry `ustc`)
Downloaded ipnet v2.4.0 (registry `ustc`)
Downloaded matches v0.1.9 (registry `ustc`)
Downloaded once_cell v1.10.0 (registry `ustc`)
Downloaded phf v0.8.0 (registry `ustc`)
Downloaded phf_generator v0.10.0 (registry `ustc`)
Downloaded rand v0.8.5 (registry `ustc`)
Downloaded scopeguard v1.1.0 (registry `ustc`)
Downloaded slab v0.4.6 (registry `ustc`)
Downloaded string_cache_codegen v0.5.2 (registry `ustc`)
Downloaded encoding_rs v0.8.31 (registry `ustc`)
Downloaded tokio-util v0.7.1 (registry `ustc`)
Downloaded tracing-core v0.1.24 (registry `ustc`)
Downloaded xml5ever v0.16.2 (registry `ustc`)
Downloaded getrandom v0.2.6 (registry `ustc`)
Downloaded httparse v1.6.0 (registry `ustc`)
Downloaded url v2.2.2 (registry `ustc`)
Downloaded lock_api v0.4.7 (registry `ustc`)
Downloaded new_debug_unreachable v1.0.4 (registry `ustc`)
Downloaded phf_codegen v0.8.0 (registry `ustc`)
Downloaded ppv-lite86 v0.2.16 (registry `ustc`)
Downloaded ryu v1.0.9 (registry `ustc`)
Downloaded time v0.1.43 (registry `ustc`)
Downloaded serde v1.0.136 (registry `ustc`)
Downloaded tracing-attributes v0.1.20 (registry `ustc`)
Downloaded futures-sink v0.3.21 (registry `ustc`)
Downloaded cc v1.0.73 (registry `ustc`)
Downloaded mime v0.3.16 (registry `ustc`)
Downloaded phf_generator v0.8.0 (registry `ustc`)
Downloaded rand_core v0.5.1 (registry `ustc`)
Downloaded smallvec v1.8.0 (registry `ustc`)
Downloaded idna v0.2.3 (registry `ustc`)
Downloaded quote v1.0.18 (registry `ustc`)
Downloaded fnv v1.0.7 (registry `ustc`)
Downloaded http-body v0.4.4 (registry `ustc`)
Downloaded openssl-sys v0.9.72 (registry `ustc`)
Downloaded rand_chacha v0.3.1 (registry `ustc`)
Downloaded tendril v0.4.3 (registry `ustc`)
Downloaded utf-8 v0.7.6 (registry `ustc`)
Downloaded indexmap v1.8.1 (registry `ustc`)
Downloaded pin-utils v0.1.0 (registry `ustc`)
Downloaded tinyvec_macros v0.1.0 (registry `ustc`)
Downloaded html5ever v0.25.2 (registry `ustc`)
Downloaded rand_chacha v0.2.2 (registry `ustc`)
Downloaded futures-core v0.3.21 (registry `ustc`)
Downloaded rand_pcg v0.2.1 (registry `ustc`)
Downloaded parking_lot v0.12.0 (registry `ustc`)
Downloaded unicode-bidi v0.3.7 (registry `ustc`)
Downloaded mac v0.1.1 (registry `ustc`)
Downloaded 106 crates (7.2 MB) in 36.00s (largest was `encoding_rs` at 1.4 MB)
Compiling cfg-if v1.0.0
Compiling autocfg v1.1.0
Compiling libc v0.2.122
Compiling proc-macro2 v1.0.37
Compiling unicode-xid v0.2.2
Compiling log v0.4.16
Compiling ppv-lite86 v0.2.16
Compiling getrandom v0.1.16
Compiling siphasher v0.3.10
Compiling syn v1.0.91
Compiling memchr v2.4.1
Compiling once_cell v1.10.0
Compiling pkg-config v0.3.25
Compiling pin-project-lite v0.2.8
Compiling cc v1.0.73
Compiling serde v1.0.136
Compiling futures-core v0.3.21
Compiling parking_lot_core v0.9.2
Compiling bytes v1.1.0
Compiling scopeguard v1.1.0
Compiling lazy_static v1.4.0
Compiling smallvec v1.8.0
Compiling new_debug_unreachable v1.0.4
Compiling itoa v1.0.1
Compiling futures-task v0.3.21
Compiling mac v0.1.1
Compiling futures-util v0.3.21
Compiling fnv v1.0.7
Compiling foreign-types-shared v0.1.1
Compiling openssl v0.10.38
Compiling utf-8 v0.7.6
Compiling precomputed-hash v0.1.1
Compiling futures-io v0.3.21
Compiling percent-encoding v2.1.0
Compiling httparse v1.6.0
Compiling futures-channel v0.3.21
Compiling hashbrown v0.11.2
Compiling slab v0.4.6
Compiling tinyvec_macros v0.1.0
Compiling pin-utils v0.1.0
Compiling matches v0.1.9
Compiling bitflags v1.3.2
Compiling futures-sink v0.3.21
Compiling native-tls v0.2.10
Compiling openssl-probe v0.1.5
Compiling try-lock v0.2.3
Compiling tower-service v0.3.1
Compiling unicode-bidi v0.3.7
Compiling encoding_rs v0.8.31
Compiling httpdate v1.0.2
Compiling regex-syntax v0.6.25
Compiling ryu v1.0.9
Compiling mime v0.3.16
Compiling base64 v0.13.0
Compiling ipnet v2.4.0
Compiling lock_api v0.4.7
Compiling indexmap v1.8.1
Compiling phf_shared v0.8.0
Compiling phf_shared v0.10.0
Compiling tracing-core v0.1.24
Compiling futf v0.1.5
Compiling http v0.2.6
Compiling foreign-types v0.3.2
Compiling openssl-sys v0.9.72
Compiling tinyvec v1.5.1
Compiling form_urlencoded v1.0.1
Compiling phf v0.8.0
Compiling tendril v0.4.3
Compiling unicode-normalization v0.1.19
Compiling http-body v0.4.4
Compiling getrandom v0.2.6
Compiling socket2 v0.4.4
Compiling num_cpus v1.13.1
Compiling time v0.1.43
Compiling quote v1.0.18
Compiling mio v0.8.2
Compiling want v0.3.0
Compiling aho-corasick v0.7.18
Compiling rand_core v0.5.1
Compiling rand_core v0.6.3
Compiling idna v0.2.3
Compiling serde_urlencoded v0.7.1
Compiling parking_lot v0.12.0
Compiling tokio v1.17.0
Compiling rand_pcg v0.2.1
Compiling rand_chacha v0.2.2
Compiling regex v1.5.5
Compiling rand_chacha v0.3.1
Compiling url v2.2.2
Compiling string_cache v0.8.4
Compiling rand v0.7.3
Compiling rand v0.8.5
Compiling tokio-native-tls v0.3.0
Compiling phf_generator v0.8.0
Compiling phf_generator v0.10.0
Compiling phf_codegen v0.8.0
Compiling string_cache_codegen v0.5.2
Compiling tracing-attributes v0.1.20
Compiling html5ever v0.25.2
Compiling markup5ever v0.10.1
Compiling xml5ever v0.16.2
Compiling tracing v0.1.33
Compiling tokio-util v0.7.1
Compiling h2 v0.3.13
Compiling markup5ever_rcdom v0.1.0
Compiling html2md v0.2.13
Compiling hyper v0.14.18
Compiling hyper-tls v0.5.0
Compiling reqwest v0.11.10
Compiling test_rust v0.1.0 (/rust/test_rust)
Finished dev [unoptimized + debuginfo] target(s) in 1m 24s
Running `target/debug/test_rust`
获取到的地址: https://www.baidu.com/
正在转换中
md放到的位置:"/root/test_rust/baidu.md"

可以看到baidu.md放到了/root/test_rust目录下,就是现所在的目录里。
使用下边的命令查看当前目录下的文件及其结构:
tree -F .

发现baidu.md这个文件就在test_rust目录下。
cat baidu.md查看里边的内容:
百度一下,你就知道body{margin:0;padding:0;text-align:center;background:#fff;height:100%}html{overflow-y:auto;color:#000;overflow:-moz-scrollbars;height:100%}body,input{font-size:12px;font-family:"PingFang SC",Arial,"Microsoft YaHei",sans-serif}a{text-decoration:none}a:hover{text-decoration:underline}img{border:0;-ms-interpolation-mode:bicubic}input{font-size:100%;border:0}body,form{position:relative;z-index:0}#wrapper{height:100%}#head\_wrapper.s-ps-islite{padding-bottom:370px}#head\_wrapper.s-ps-islite .s\_form{position:relative;z-index:1}#head\_wrapper.s-ps-islite .fm{position:absolute;bottom:0}#head\_wrapper.s-ps-islite .s-p-top{position:absolute;bottom:40px;width:100%;height:181px}#head\_wrapper.s-ps-islite #s\_lg\_img{position:static;margin:33px auto 0 auto;left:50%}#form{z-index:1}.s\_form\_wrapper{height:100%}#lh{margin:16px 0 5px;word-spacing:3px}.c-font-normal{font:13px/23px Arial,sans-serif}.c-color-t{color:#222}.c-btn,.c-btn:visited{color:#333!important}.c-btn{display:inline-block;overflow:hidden;font-family:inherit;font-weight:400;text-align:center;vertical-align:middle;outline:0;border:0;height:30px;width:80px;line-height:30px;font-size:13px;border-radius:6px;padding:0;background-color:#f5f5f6;cursor:pointer}.c-btn:hover{background-color:#315efb;color:#fff!important}a.c-btn{text-decoration:none}.c-btn-mini{height:24px;width:48px;line-height:24px}.c-btn-primary,.c-btn-primary:visited{color:#fff!important}.c-btn-primary{background-color:#4e6ef2}.c-btn-primary:hover{background-color:#315efb}a:active{color:#f60}#wrapper{position:relative;min-height:100%}#head{padding-bottom:100px;text-align:center}#wrapper{min-width:1250px;height:100%;min-height:600px}#head{position:relative;padding-bottom:0;height:100%;min-height:600px}.s\_form\_wrapper{height:100%}.quickdelete-wrap{position:relative}.tools{position:absolute;right:-75px}.s-isindex-wrap{position:relative}#head\_wrapper.head\_wrapper{width:auto}#head\_wrapper{position:relative;height:40%;min-height:314px;max-height:510px;width:1000px;margin:0 auto}#head\_wrapper .s-p-top{height:60%;min-height:185px;max-height:310px;position:relative;z-index:0;text-align:center}#head\_wrapper input{outline:0;-webkit-appearance:none}#head\_wrapper .s\_btn\_wr,#head\_wrapper .s\_ipt\_wr{display:inline-block;zoom:1;background:0 0;vertical-align:top}#head\_wrapper .s\_ipt\_wr{position:relative;width:546px}#head\_wrapper .s\_btn\_wr{width:108px;height:44px;position:relative;z-index:2}#head\_wrapper .s\_ipt\_wr:hover #kw{border-color:#a7aab5}#head\_wrapper #kw{width:512px;height:16px;padding:12px 16px;font-size:16px;margin:0;vertical-align:top;outline:0;box-shadow:none;border-radius:10px 0 0 10px;border:2px solid #c4c7ce;background:#fff;color:#222;overflow:hidden;box-sizing:content-box}#head\_wrapper #kw:focus{border-color:#4e6ef2!important;opacity:1}#head\_wrapper .s\_form{width:654px;height:100%;margin:0 auto;text-align:left;z-index:100}#head\_wrapper .s\_btn{cursor:pointer;width:108px;height:44px;line-height:45px;padding:0;background:0 0;background-color:#4e6ef2;border-radius:0 10px 10px 0;font-size:17px;color:#fff;box-shadow:none;font-weight:400;border:none;outline:0}#head\_wrapper .s\_btn:hover{background-color:#4662d9}#head\_wrapper .s\_btn:active{background-color:#4662d9}#head\_wrapper .quickdelete-wrap{position:relative}#s\_top\_wrap{position:absolute;z-index:99;min-width:1000px;width:100%}.s-top-left{position:absolute;left:0;top:0;z-index:100;height:60px;padding-left:24px}.s-top-left .mnav{margin-right:31px;margin-top:19px;display:inline-block;position:relative}.s-top-left .mnav:hover .s-bri,.s-top-left a:hover{color:#315efb;text-decoration:none}.s-top-left .s-top-more-btn{padding-bottom:19px}.s-top-left .s-top-more-btn:hover .s-top-more{display:block}.s-top-right{position:absolute;right:0;top:0;z-index:100;height:60px;padding-right:24px}.s-top-right .s-top-right-text{margin-left:32px;margin-top:19px;display:inline-block;position:relative;vertical-align:top;cursor:pointer}.s-top-right .s-top-right-text:hover{color:#315efb}.s-top-right .s-top-login-btn{display:inline-block;margin-top:18px;margin-left:32px;font-size:13px}.s-top-right a:hover{text-decoration:none}#bottom\_layer{width:100%;position:fixed;z-index:302;bottom:0;left:0;height:39px;padding-top:1px;overflow:hidden;zoom:1;margin:0;line-height:39px;background:#fff}#bottom\_layer .lh{display:inline;margin-right:20px}#bottom\_layer .lh:last-child{margin-left:-2px;margin-right:0}#bottom\_layer .lh.activity{font-weight:700;text-decoration:underline}#bottom\_layer a{font-size:12px;text-decoration:none}#bottom\_layer .text-color{color:#bbb}#bottom\_layer a:hover{color:#222}#bottom\_layer .s-bottom-layer-content{text-align:center}
[新闻](//news.baidu.com/)[hao123](//www.hao123.com/)[地图](//map.baidu.com/)[直播](//live.baidu.com/)[视频](//haokan.baidu.com/?sfrom=baidu-top)[贴吧](//tieba.baidu.com/)[学术](//xueshu.baidu.com/)
[更多](//www.baidu.com/more/)
[登录](//www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1)
<img src="//www.baidu.com/img/flexible/logo/pc/index.png" height="129" width="270" />
[](//www.baidu.com/)
[关于百度](//home.baidu.com/)
[About Baidu](//ir.baidu.com/)
[使用百度前必读](//www.baidu.com/duty)
[帮助中心](//help.baidu.com/)
[京公网安备11000002000001号](//www.beian.gov.cn/portal/registerSystemInfo?recordcode=11000002000001)
[京ICP证030173号](//beian.miit.gov.cn/)
互联网药品信息服务资格证书 (京)-经营性-2017-0020
[信息网络传播视听节目许可证 0110516](//www.baidu.com/licence/)
var date=new Date,year=date.getFullYear();document.getElementById("year").innerText="©"+year+" Baidu "
版权声明:本文为qq_42108074原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。