相关疑难解决方法(0)

如何从tests目录中的文件访问src目录中的文件?

我有一个项目布局,如下所示:

src/
    int_rle.rs
    lib.rs
tests/
    test_int_rle.rs
Run Code Online (Sandbox Code Playgroud)

该项目编译cargo build,但我无法运行测试cargo test.我收到了错误

error[E0432]: unresolved import `int_rle`. There is no `int_rle` in the crate root
 --> tests/test_int_rle.rs:1:5
  |
1 | use int_rle;
  |     ^^^^^^^

error[E0433]: failed to resolve. Use of undeclared type or module `int_rle`
 --> tests/test_int_rle.rs:7:9
  |
7 |         int_rle::IntRle { values: vec![1, 2, 3] }
  |         ^^^^^^^^^^^^^^^ Use of undeclared type or module `int_rle`

error: aborting due to 2 previous errors

error: Could not compile `minimal_example_test_directories`.
Run Code Online (Sandbox Code Playgroud)

我的代码:

// …
Run Code Online (Sandbox Code Playgroud)

rust rust-cargo

1
推荐指数
1
解决办法
862
查看次数

标签 统计

rust ×1

rust-cargo ×1