具有多个板条箱的工作区中未解决的导入 Rust

问题描述 投票:0回答:1

我有一个包含 3 个箱子、game_nft、后端和测试的工作区。

这是我的根 Cargo.toml

[workspace]
members = ["backend", "game_nft", "tests"]
resolver = "2"

我的测试/Cargo.toml:

[package]
name = "tests"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
candid = "0.10.6"
pocket-ic = "6.0.0"
game_nft = { path = "../game_nft" }

为了非常清楚,这是文件结构:

root/
├── Cargo.toml
├── Cargo.lock
├── game_nft/
│   ├── Cargo.toml
│   └── src/
├── test/
│   ├── Cargo.toml
│   └── src/
├── backend/
    ├── Cargo.toml
    └── src/

在我的测试/src/lib.rs 中我这样做

use game_nft;

那么为什么我会收到错误:

 error[E0432]: unresolved import `game_nft`
 --> tests/src/lib.rs:3:5
  |
3 | use game_nft;
  |     ^^^^^^^^ no external crate `game_nft`

这里是 game_nft/Cargo.toml:

[package]
name = "game_nft"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
candid = "0.10.6"
ic-cdk = "0.13.1"
ic-stable-structures = "0.6.3"
icrc-ledger-types = "0.1.5"
serde = "1.0.197"
icrc-nft-types = { git = "https://github.com/pramitgaha21/icrc-nft-types.git" }
ciborium = "0.2.2"
serde_bytes = "0.11"

我也尝试过语法

use crate::game_nft;
并收到相同的错误消息。

rust import rust-crates
1个回答
0
投票

A

cdylib
不能在 Rust 中使用。您可以将
game_nft
制作为
lib
dylib
rlib
类型。您可以在此处阅读有关这些内容的更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.