当前位置: 代码迷 >> 综合 >> rust: 引用第三方库(Cargo.toml、Cargo.lock文件)
  详细解决方案

rust: 引用第三方库(Cargo.toml、Cargo.lock文件)

热度:97   发布时间:2023-12-12 15:58:17.0

接下来我要使用随机数生成函数,这个函数在 rand 库中。我们在 Cargo.toml 文件中的依赖项中,加入对 rand 的依赖说明。

[package]
name = "game"
version = "0.1.0"
authors = ["xuyeping"]
edition = "2018"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html[dependencies]
rand = "0.3.14"

“0.3.14” 说明我们要加入API与该版本号兼容的第三方库。运行 cargo build 命令,系统自动下载该库代码。

>>cargo runUpdating crates.io indexDownloaded libc v0.2.81Downloaded rand v0.3.23Downloaded rand v0.4.6Downloaded winapi v0.3.9Downloaded 4 crates (1.8 MB) in 3.41s (largest was `winapi` at 1.2 MB)Compiling winapi v0.3.9Compiling libc v0.2.81Compiling rand v0.4.6Compiling rand v0.3.23Compiling game v0.1.0 (E:\DiskZ\rust\0003-game)Finished dev [unoptimized + debuginfo] target(s) in 1m 57s

编译过程中自动生成的 Cargo.lock 文件,记录了相关资源信息,保证我们以后可以重新构建。

# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"[[package]]
name = "game"
version = "0.1.0"
dependencies = ["rand 0.3.23",
][[package]]
name = "libc"
version = "0.2.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"[[package]]
name = "rand"
version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c"
dependencies = ["libc","rand 0.4.6",
][[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
dependencies = ["fuchsia-cprng","libc","rand_core 0.3.1","rdrand","winapi",
][[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = ["rand_core 0.4.2",
][[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = ["rand_core 0.3.1",
][[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = ["winapi-i686-pc-windows-gnu","winapi-x86_64-pc-windows-gnu",
][[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

我看了一下,下载的代码包保存在 .cargo 文件夹下:
在这里插入图片描述

  相关解决方案