我正在尝试创建一个包含库和一个或多个二进制文件的包。我查看了Rust package with both a library and a binary?和the Rust book section on crates and modules,但在尝试编译时仍然遇到错误。
我已经包含了每个文件的相关部分(我认为)。
../ cargo.toml:
[package]
name = "plotmote"
version = "0.1.0"
authors = ["Camden Narzt <my@nice.email>"]
[lib]
name = "lib_plotMote"
path = "src/lib.rs"
[[bin]]
name = "plotMote"
path = "src/main.rs"
lib.rs:
pub mod lib_plotMote;
lib_plotMote / mod.rs:
pub mod LogstreamProcessor;
lib_plotMote / LogstreamProcessor.rs:
pub struct LogstreamProcessor {
main.rs:
extern crate lib_plotMote;
use lib_plotMote::LogStreamProcessor;
错误:
cargo build
Compiling plotmote v0.1.0 (file:///Users/camdennarzt/Developer/Rust/plotmote)
main.rs:6:5: 6:37 error: unresolved import `lib_plotMote::LogStreamProcessor`. There is no `LogStreamProcessor` in `lib_plotMote` [E0432]
答案 0 :(得分:2)
这应该有效:
use lib_plotMote::lib_plotMote::LogStreamProcessor;
第一个lib_plotMote
来自extern crate
,第二个来自您在库包中定义的模块:
pub mod lib_plotMote;
因此,库包包含一个模块,巧合的是,它与包装箱本身具有相同的名称。
另外,正如@starblue注意到的那样,结构(LogstreamProcessor
)的声明网站及其使用网站(LogStreamProcessor
)中的大小写不匹配。这也应该修复。
正如旁注所示,我建议您遵循惯用的命名约定,并避免使用模块/包名称中的camelCase。