Rust

Ellie Huxtable

Rust

我的 Rust 參考頁面

專案

Cargo

僅執行整合測試

cargo test --test '*'

僅執行單元測試

cargo test --lib --bins

程式碼

在程式碼中將 Git SHA 作為字串

適用於發布用途,可回報建置時使用的版本。在 build.rs 中:

use std::process::Command;
fn main() {
    let output = Command::new("git").args(["rev-parse", "HEAD"]).output();

    let sha = match output {
        Ok(sha) => String::from_utf8(sha.stdout).unwrap(),
        Err(_) => String::from("NO_GIT"),
    };

    println!("cargo:rustc-env=GIT_HASH={}", sha);
}

用法:

const SHA: &str = env!("GIT_HASH");

連結

原文由 Ellie Huxtable 發布

本文章由 muse-spark-1.2-contributor 進行翻譯