【问题标题】:Unresolved import `calamine`未解决的导入“炉甘石”
【发布时间】:2023-01-12 04:35:29
【问题描述】:

我想用 Rust 链接我的 excel 数据库。 我写了下面的代码,但发生了一些错误。

use calamine::{open_workbook,Render,xlsx};// 

fn main(){
    let xl_book_path="Your Excle Book Path.xlsx";
    let met wb: Xlsx<_> = opne_workbook(Xl_book_path).expect("cannot open xl book");
}
error[E0432]: unresolved import `calamine`
  --> Aut.rs:1:5
   | 1 | use calamine::{open_workbook,Render,xlsx};
       |     ^^^^^^^^ maybe a missing crate `calamine`?
   |   = help: consider adding `extern crate calamine` to use the `calamine` crate

error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0432`.

我认为原因是 Cargo.toml 中缺少calamine, 所以我在 Cargo.toml 中添加了炉甘石。

[dependencies] calamine = "0.18.0"

但错误仍然出现。 我该如何解决这个问题?

【问题讨论】:

  • 你不是故意在你的代码中添加 extern crate calamine 吗?
  • 谢谢回复。我不知道“extern crate calamine”,所以我用 Cargo.toml 添加了炉甘石代码(第 8,9 行)。你的意思是需要添加代码?
  • 这取决于您在 cargo.toml 中设置的 Rust 版本。里面有“edition = ...”行吗?
  • 您应该按原样发布您的 cargo.toml、main.rs 的重要部分(不是手工重写——请注意您在上面的“opne_workbook”中有错字),以及您用来尝试构建/运行程序。这将有助于理解问题。
  • 你是用 Cargo 搭建,还是直接调用rustc

标签: rust


【解决方案1】:

要添加依赖项,[dependencies] 部分应如下所示:

[dependencies]
calamine = "0.19.1"

你不能把它们放在同一行。

然后,您可以在项目目录(Cargo.toml 所在的位置)中使用 cargo run 运行项目,它应该可以找到 calamine

【讨论】:

    【解决方案2】:

    同意cafce25的回答,2022年10月以来正确的依赖是calamine = "0.19.1"。 原代码中有一些错别字和大小写错误,所以这里是更正后的代码:

    use calamine::{open_workbook,Reader,Xlsx};
    
    fn main(){
        let xl_book_path="Your Excle Book Path.xlsx";
        #[allow(unused_mut)]
        #[allow(unused_variables)]
        let mut wb: Xlsx<_> = open_workbook(xl_book_path).expect("cannot open xl book");
    }
    

    在编写 Rust 代码时,您应该注意名称,因为该语言区分大小写:

    1. 第 1 行:已更改 Ren为了Reader
    2. 第 1 行:已更改Xlsx 到Xlsx
    3. 第 7 行:更改了 m电子转至mut
    4. 第 7 行:更改了操作_工作簿open_workbook
    5. 第 7 行:已更改Xl_book_path 到 xl_book_path

      额外资源:

      希望能帮你解决问题就好了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-01
      • 2015-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 1970-01-01
      相关资源
      最近更新 更多