Rust Cargo使用总结

栏目: 编程语言 · Rust · 发布时间: 7年前

内容简介:文档列表见: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 文档。


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

虚拟现实:最后的传播

虚拟现实:最后的传播

聂有兵 / 中国发展出版社 / 2017-4-1 / 39.00

本书对“虚拟现实”这一诞生自70年代却在今天成为热门话题的概念进行了历史发展式的分析和回顾,认为虚拟现实是当今最重大的社会变革的技术因素之一,对虚拟现实在未来百年可能给人类社会的各个层面带来的影响进行说明,结合多个大众媒介的发展趋势,合理地推演未来虚拟现实在政治、经济、文化等领域的态势,并基于传播学理论框架提出了几个新的观点。对于普通读者,本书可以普及一般的虚拟现实知识;对于传媒行业,本书可以引导......一起来看看 《虚拟现实:最后的传播》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具