Rust学习笔记

Rust由非盈利组织Mozilla基金会开发,像著名的Mozilla Firefox浏览器和MDN Web Docs都出自该基金会 安装 官方推荐使用Rustup来安装(Rustup是rust的安装器和版本管理工具) 通过rustup-init来安装Rust https://www.rust-lang.org/zh-CN/tools/install windows直接安装pustup-init.exe来安装(需联网),默认通过vc安装,建议选择2自定义安装 Linux或者macOS则直接执行以下命令 curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs | sh 注意:Rust的一些包,可能还依赖C编译器,因此最好安装一下GCC 检查是否安装完成 rustc –version 如果喜欢用Visual Studio Code开发,可搭配rust-analyzer插件来使用 更新rust rustup update 卸载rust和rustup rustup self uninstall 在安装rustup的同时也会安装Cargo Cargo是rust的项目构建工具和包管理器 检查是否安装成功 cargo –version 创建第一个rust项目 cargo new halloword 其中Cargo.toml文件是项目的依赖库文件 通过编辑Cargo.toml文件来添加依赖 rust依赖可通过https://crates.io/查找 [package] name = "hallo_word" version = "0.0.1" edition = "2021" [dependencies] hyper = "0.14.20" # 来自https://crates.io/ # hyper = { git = "https://github.com/hyperium/hyper" } # 来自第三方社区 # hyper = { path = "....

2022-03-28 · 7 min · Me