我怎么搞乱了这些模块?

问题描述 投票:0回答:1

我正在尝试创建一个包含库和一个或多个二进制文件的板条箱。我查看了包含库和二进制文件的包?Rust 书籍中关于板条箱和模块的部分,但当我尝试编译时仍然遇到错误。

我已经包含了每个文件的相关部分(我认为)。

../cargo.toml:

[package]
name = "plotmote"
version = "0.1.0"
authors = ["Camden Narzt <[email protected]>"]

[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]
rust module rust-cargo rust-crates
1个回答
2
投票

这应该有效:

use lib_plotMote::lib_plotMote::LogStreamProcessor;

第一个

lib_plotMote
来自
extern crate
,第二个来自您在库箱中定义的模块:

pub mod lib_plotMote;

因此,库 crate 包含一个模块,巧合的是,该模块与 crate 本身具有相同的名称。

此外,正如 @starblue 所注意到的,结构的声明站点 (

LogstreamProcessor
) 及其使用站点 (
LogStreamProcessor
) 存在大小写不匹配。这也应该得到解决。

作为旁注,我建议您遵循惯用的命名约定,并避免在模块/板条箱名称中使用驼峰式命名法。

© www.soinside.com 2019 - 2024. All rights reserved.