rust编程世界

win winget install Rustlang.Rustup
ubuntu snap install rustup
rocky dnf install rust cargo
脚本 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

  • 命令
    rustc -V 版本
    rustup update 升级
    rustup self uninstall 卸载
    cargo -V 包管理
    rustup doc本地文档
    rustup install 1.75.0 # 安装特定版本
    rustup default 1.75.0 # 设置为默认版本
  • 镜像
    使用国内镜像,在C:\Users\yoby.cargo\config.toml创建文件,文件名就是”config”,而不是”.config”!!!
    [source.crates-io]
    replace-with = 'aliyun'
    [source.aliyun]
    registry = "sparse+https://mirrors.aliyun.com/crates.io-index/"
  • vscode rls 和 Native Debug 两个扩展,演示
    cargo new hello
    cd hello
    cargo build 生成
    cargo build --release 正式版生成
    cargo run
    cargo check 检测
    • 最佳优化
      [profile.release]
      opt-level = "z" 3是生成最小
      lto = "fat"     true链接优化但是编译短时间
      strip = "symbols"  true也可以
  • hello world
fn greet_world() {
    let southern_germany = "Grüß Gott!";
    let chinese = "世界,你好";
    let english = "World, hello";
    let regions = [southern_germany, chinese, english];
    for region in regions {
        println!("{}", region);
    }
}
fn main() {
    greet_world();
}
  • 常见库
    cargo install slint-lsp slint语言
    cargo install cargo-generate ratatui
    cargo install rustlings 练习
作者:Yoby  创建时间:2020-07-25 00:08
最后编辑:Yoby  更新时间:2025-10-15 01:40
上一篇:
下一篇: