rust

rust官网

https://www.rust-lang.org/tools/install

模块下载 https://crates.io/search

visualCode 插件

rust-analizer
Rust Syntax

rustVersion

rustc --version
rustc [file.rs] //编译文件

rustup

一个rusttools工具可以帮我们快速做一些事。

rustup help //查看列表
rustup update //版本升级
rustup self uninstall //卸载
rustup doc //doc文档

cargo

cargo是rust的命令行工具,用于创建项目,编译,执行。在vsCode中的执行实质上还是执行了此命令。

cargo new [my_project] //创建项目
cargo fmt //格式化,类似 rustfmt [filename]
cargo build //建立debug
cargo b //build缩写
cargo build --release //创建发行版
cargo run //编译并运行
cargo run --quiet //不显示编译,只显示执行信息
cargo run -q
cargo r //run的缩写
cargo check //检查编译,同时给出可能建议
cargo clean // 清理
cargo add [module] //加载新的模块

macro

宏是编译时执行,可接收不定参,不同于函数,定义使用macro_rules!,使用时也需要带感叹号。

// 此为定义的宏
macro_rules! say_hi {
    ($name:expr) => {
        println!("Hi......: {}!", $name)
    };
}

fn add(a: i32, b: i32) -> i32 {
    return a + b;
}

fn main() {
    // 宏是会在编译时,找到具体要执行的语句而输出内部
    println!("Hello, world!");
    let name = "Lilei";
    say_hi!(name);
    add(32, 24);
}

posted on 2025-03-16 11:02  zhaoqiang1980  阅读(15)  评论(0)    收藏  举报