0

I'm trying to create a crate that has a library and one or more binaries. I've looked at Rust package with both a library and a binary? and the Rust book section on crates and modules but am still running into errors when I try and compile.

I've included the relevant sections of each file (I think).

../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;

error:

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]
Community
  • 1
  • 1
Camden Narzt
  • 2,271
  • 1
  • 23
  • 42
  • `LogStreamProcessor` is not the same as `LogstreamProcessor` (`s` has different case). Also better follow the Rust code style with lowercase names for modules. https://doc.rust-lang.org/style/ – starblue Feb 16 '16 at 07:01

1 Answers1

2

This should work:

use lib_plotMote::lib_plotMote::LogStreamProcessor;

The first lib_plotMote comes from extern crate, and the second one comes from the module you have defined in the library crate:

pub mod lib_plotMote;

Therefore, the library crate contains one module which, coincidentally, has the same name as the crate itself.

Also, as @starblue has noticed, you have case mismatch in the declaration site of the structure (LogstreamProcessor) and its use site (LogStreamProcessor). This should also be fixed.

As as side note, I suggest you to follow the idiomatic naming convention and avoid camelCase in module/crate names.

Vladimir Matveev
  • 120,085
  • 34
  • 287
  • 296