【发布时间】:2022-09-23 07:28:12
【问题描述】:
我是 Rust 的几个小时新手。 我正在尝试从https://docs.rs/docx/latest/docx/ 编译示例代码以使用 docx crate。
这是示例代码:
use docx::document::Paragraph;
use docx::DocxFile;
let docx = DocxFile::from_file(\"origin.docx\").unwrap();
let mut docx = docx.parse().unwrap();
let para = Paragraph::default().push_text(\"Lorem Ipsum\");
docx.document.push(para);
docx.write_file(\"origin_appended.docx\").unwrap();
我编辑了我的 Cargo.toml 以包含 docx 依赖项。 这是我得到的完整错误:
Compiling bzip2-sys v0.1.11+1.0.8
Compiling jetscii v0.4.4
Compiling quote v1.0.21
Compiling time v0.1.44
error: generic parameters may not be used in const operations
--> /home/thwart/.cargo/registry/src/github.com-1ecc6299db9ec823/jetscii-0.4.4/src/simd.rs:109:13
|
109 | T::CONTROL_BYTE,
| ^^^^^^^^^^^^^^^ cannot perform const operation using `T`
|
= note: type parameters may not be used in const expressions
error: generic parameters may not be used in const operations
--> /home/thwart/.cargo/registry/src/github.com-1ecc6299db9ec823/jetscii-0.4.4/src/simd.rs:148:13
|
148 | T::CONTROL_BYTE,
| ^^^^^^^^^^^^^^^ cannot perform const operation using `T`
|
= note: type parameters may not be used in const expressions
error: could not compile `jetscii` due to 2 previous errors
为什么 Rust 编译 jetscii?如何修复此错误? 谢谢!
-
您使用的是哪个版本的 Rust?
-
rustc -V = 1.62.1
-
@PitaJ 那是
jetscii的旧版本。可能是docx应该更新到新版本。虽然总的来说这对我来说很奇怪,因为 Rust 编译器不应该破坏曾经编译过的代码。 -
所以看起来问题出在 \'docx\' crate 而不是上面的示例代码。我将 docx 作为依赖项添加到我的 hello-world 项目中并得到了同样的错误。
-
@ed_is_my_name 是的,我想。编译器错误出现在
docxcrate 的编译中,而不是您的代码中。