Rust Cargo使用總結

2021-09-11 09:02:53 字數 2079 閱讀 5537

文件列表見:rust 移動端跨平台複雜圖形渲染專案開發系列總結(目錄)

2018.12.23 更新cargo workspace feature編譯的命令執行路徑問題

cargo用於組織rust專案,比直接用rustc編譯多個原始檔更方便。本文件介紹我們開發過程中用到的cargo功能與小技巧。完整資訊可閱讀the cargo book。

rev表示要使用的commit id,可簡寫成前7個字元,因為git commit id前7個字元可算出完整的41個字元值。

[dependencies]

gfx-hal =

// 或者寫成多行

[dependencies.gfx-hal]

git = ""

version = "0.1.0"

rev = "bd7f058efe78d7626a1cc6fbc0c1d3702fb6d2e7"

複製**

git倉庫位址需要支援https訪問,如果是http需要額外配置,比較麻煩。

[dependencies]

hello_utils =

複製**

path是相對於本專案cargo.toml檔案的被依賴專案的cargo.toml的位置,填錯將找不到檔案,且編譯報錯。詳細資訊參考the cargo book/specifying-dependencies

/// open the physical device with `count` queues from some active queue family. the family is

/// the first that both provides the capability `c`, supports at least `count` queues, and for

/// which `selector` returns true.

////// # examples

////// ```no_run

/// # extern crate gfx_backend_empty as empty;

/// # extern crate gfx_hal as hal;

/// use hal::general;

/// # fn main()

/// ```

////// # return

////// returns the same errors as `open` and `initializationfailed` if no suitable

/// queue family could be found.

pubfn

open_with

( &self,

count: usize,

selector: f,

) -> result

<(b::device, queuegroup), devicecreationerror>

where

f: fn(&b::queuefamily) -> bool,

c: capability,

).next();

let priorities = vec![1.0; count];

let (id, families) = match requested_family ;

let gpu = self.physical_device.open(&families)?;

ok((device, queues.take(id).unwrap()))

}複製**

前面examples**可以用rust-skeptic進行測試,具體做法可閱讀rust-skeptic文件。

對於cargo workspace下有多個project的情況,如果對其中乙個project進行feature編譯執行或做單元測試,一定要在此專案的cargo.toml或src內執行,否則cargo會忽悠cargo test或cargo build --features=your_feature所指定的feature,這是個很小卻容易踩中的坑。

rust cargo 常用命令

clippy lint your project using clippy.說明 檢查 規範,並給出優化方案 常用 命令 cargo clippy cargo expand print the result of macro expansion and derive expansion.說明 der...

運維經 第9章 rust cargo 加速

因為本人主營業務是c 那麼就要更了解c 的敵人 rust 聽說她要取代c 但不得不說,rust的工具鏈還是非常值得稱讚的,後續會開幾期來講講rust工具鏈,今天還是談談加速。找到cargo的配置,cargo config base frank deepin cd cargo base frank d...

EJunGrid使用總結

1 1。0版沒有實現垂直方向上的對齊,procedure tobgui reportdesign.griddrawcelltext acanvas tcanvas const arect trect const acoord tpoint agrid tzjgrid const text strin...