内容简介:文档列表见:Cargo用于组织Rust项目,比直接用rustc编译多个源文件更方便。本文档介绍我们开发过程中用到的Cargo功能与小技巧。完整信息可阅读The Cargo Book。rev表示要使用的commit id,可简写成前7个字符,因为git commit id前7个字符可算出完整的41个字符值。
文档列表见: Rust 移动端跨平台复杂图形渲染项目开发系列总结(目录)
Cargo用于组织Rust项目,比直接用rustc编译多个源文件更方便。本文档介绍我们开发过程中用到的Cargo功能与小技巧。完整信息可阅读The Cargo Book。
Cargo使用依赖项目的指定git commit
rev表示要使用的commit id,可简写成前7个字符,因为git commit id前7个字符可算出完整的41个字符值。
[dependencies] gfx-hal = { version = "0.1.0", git = "https://github.com/gfx-rs/gfx", rev = "bd7f058efe78d7626a1cc6fbc0c1d3702fb6d2e7" } // 或者写成多行 [dependencies.gfx-hal] git = "https://github.com/gfx-rs/gfx" version = "0.1.0" rev = "bd7f058efe78d7626a1cc6fbc0c1d3702fb6d2e7" 复制代码
git仓库地址需要支持https访问,如果是http需要额外配置,比较麻烦。
引用本地Rust项目
[dependencies] hello_utils = { path = "hello_utils", version = "0.1.0" } 复制代码
path是相对于本项目Cargo.toml文件的被依赖项目的Cargo.toml的位置,填错将找不到文件,且编译报错。详细信息参考 The Cargo Book/specifying-dependencies
测试Rust代码中的Markdown代码段
/// 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() { /// /// # let mut adapter: hal::Adapter<empty::Backend> = return; /// let (device, queues) = adapter.open_with::<_, General>(1, |_| true).unwrap(); /// # } /// ``` /// /// # Return /// /// Returns the same errors as `open` and `InitializationFailed` if no suitable /// queue family could be found. pub fn open_with<F, C>( &self, count: usize, selector: F, ) -> Result<(B::Device, QueueGroup<B, C>), DeviceCreationError> where F: Fn(&B::QueueFamily) -> bool, C: Capability, { use queue::QueueFamily; let requested_family = self .queue_families .iter() .filter(|family| { C::supported_by(family.queue_type()) && selector(&family) && count <= family.max_queues() }) .next(); let priorities = vec![1.0; count]; let (id, families) = match requested_family { Some(family) => (family.id(), [(family, priorities.as_slice())]), _ => return Err(DeviceCreationError::InitializationFailed), }; let Gpu { device, mut queues } = self.physical_device.open(&families)?; Ok((device, queues.take(id).unwrap())) } 复制代码
前面 Examples
代码可以用rust-skeptic进行测试,具体做法可阅读 rust-skeptic
文档。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。