这是一个以前从来没有发生过的问题,在我添加了Excel函数后突然出现了

use crate::common::offic::excel; // <<--
use clap::Parser;
use jni::objects::*;
use jni::JNIEnv;
use std::path::Path;  
use HspiceCompiler::hspice::spice; // <<-- 

#[derive(Parser, Debug)]
#[command(author, version, about)]
pub struct Args {
    #[clap(help = "Hspice file name")]
    pub file_name: String,
    #[clap(short, long)]
    pub output_path: String,
}

fn main() {
    let args = Args::parse();

    let spice_file = Path::new(&args.file_name);

    let output_path = Path::new(&args.output_path);

    loading(args);

    spice_file.try_exists().expect("Can't access hspice file");
    let mut reader = spice::Reader::new();
    let data_iter = reader.read(spice_file);
    reader.analysis_iter(data_iter);

    excel::write_to_excel(data_iter, output_path);
}
fn loading(args: Args) {
...
}

错误:

error[E0433]: failed to resolve: could not find `common` in the crate root
 --> src/bin/run.rs:1:12
  |
1 | use crate::common::offic::excel;
  |            ^^^^^^ could not find `common` in the crate root
error[E0433]: failed to resolve: use of undeclared type `HspiceCompiler`
 --> src/bin/run.rs:5:5
  |
5 | use HspiceCompiler::common::offic::excel;
  |     ^^^^^^^^^^^^^^ use of undeclared type `HspiceCompiler`

我的GitHub-&gt;Run.RS:https://github.com/llllishuo/menghan_Hspice_Compiler/blob/main/src/bin/run.rs

推荐答案

crate指的是crate的根模块,在本例中是src/bin/run.rs.如果你想引用同一package中的库箱,你需要用包的名称来引用它.

use HspiceCompiler::common::offic::excel;

但是,您的包当前没有Ruust库,因为您的Cargo.toml只包含一个dynamic system library:

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

如果您希望将该库也用作 rust 库,则还应包含lib个.

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

这也将修复您的第二个错误.

Rust相关问答推荐

收集RangeInclusive T到Vec T<><>

不能在一个代码分支中具有不变的自身borrow ,而在另一个代码分支中具有可变的self borrow

我是否可以在Ruust中修改 struct 实例上的字符串,以使其在修改后具有相同的字符串生存期?

习语选项<;T>;到选项<;U>;当T->;U用From定义

为什么我需要 to_string 函数的参考?

为什么将易错函数的泛型结果作为泛型参数传递 infer ()?不应该是暧昧的吗?

write_buffer 不写入缓冲区而是输出零 WGPU

Rust中是否可以在不复制的情况下从另一个不可变向量创建不可变向量?

枚举的利基优化如何在 Rust 中工作?

为什么不可变特征的实现可以是可变的?

从嵌入式 Rust 中的某个时刻开始经过的时间

在 Rust 中使用 `SecTrustSettingsSetTrustSettings` 绑定导致 `errSecInternalComponent`

了解 Rust 闭包:为什么它们持续持有可变引用?

如果我不想运行析构函数,如何移出具有析构函数的 struct ?

Rust,我如何正确释放堆分配的内存?

从函数返回 u32 的数组/切片

有没有办法阻止 rust-analyzer 使非活动代码变暗?

当特征函数依赖于为 Self 实现的通用标记特征时实现通用包装器

如何断言代码不会在测试中编译?

为什么 Bevy 的 Trait 边界不满足 Rapier 物理插件?