我怎么弄乱这些模块?
How am I messing up these modules?
我正在尝试创建一个包含库和一个或多个二进制文件的箱子。我查看了 Rust package with both a library and a binary? and 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]
这应该有效:
use lib_plotMote::lib_plotMote::LogStreamProcessor;
第一个 lib_plotMote
来自 extern crate
,第二个来自您在库 crate 中定义的模块:
pub mod lib_plotMote;
因此,库 crate 包含一个模块,巧合的是,它与 crate 本身同名。
此外,正如@starblue 所注意到的,您在结构的声明站点 (LogstreamProcessor
) 及其使用站点 (LogStreamProcessor
) 中存在大小写不匹配的情况。这也应该得到解决。
作为旁注,我建议您遵循惯用的命名约定并避免在 module/crate 名称中使用驼峰式命名。
我正在尝试创建一个包含库和一个或多个二进制文件的箱子。我查看了 Rust package with both a library and a binary? and 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]
这应该有效:
use lib_plotMote::lib_plotMote::LogStreamProcessor;
第一个 lib_plotMote
来自 extern crate
,第二个来自您在库 crate 中定义的模块:
pub mod lib_plotMote;
因此,库 crate 包含一个模块,巧合的是,它与 crate 本身同名。
此外,正如@starblue 所注意到的,您在结构的声明站点 (LogstreamProcessor
) 及其使用站点 (LogStreamProcessor
) 中存在大小写不匹配的情况。这也应该得到解决。
作为旁注,我建议您遵循惯用的命名约定并避免在 module/crate 名称中使用驼峰式命名。