《陈天 · Rust 编程第一课》学习笔记Day 1 搭建开发环境

《陈天 · Rust 编程第一课》学习笔记Day 1 搭建开发环境

先从安装运行开始,搞出开发环境。

安装

Unix:直接运行

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

安装完成后,就可以创建项目了。

cargo new first

当运行完,就会创建一个名为first的项目文件夹。

默认main.rs里就是经典的 hello world。

fn main() {
    println!("Hello world!");
}

接着在Cargo.toml的依赖项里加入reqwest和html2md

[dependencies]
reqwest = { version = "0.11", features = ["blocking"] }
html2md = "0.2"

main.rs修改如下:

use std::fs;
fn main() {
    let url = "https://www.rust-lang.org/";
    let output = "rust.md";
    println!("Fetching url: {}", url);