Failing to find a module [SOLVED]


#1

Hi.
I am just trying to create my first module.
File system structure:

src :
lib.rs
client.rs
main.rs

contents of lib.rs:
pub mod client;

contets of client.rs
fn connect () {}

and contents of main.rs

extern crate communicator;

fn main() {
    communicator::client::connect();
}

and when I am trying to build project with “cargo build” I get this error:

error[E0433]: failed to resolve. Could not find client in communicator
–> src/main.rs:4:5
|
4 | communicator::client::connect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Could not find client in communicator

error: aborting due to previous error

error: Could not compile communicator.

Caused by:
process didn’t exit successfully: rustc --crate-name communicator src/main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=8bad32256e86bfcc -C extra-filename=-8bad32256e86bfcc --out-dir /home/alireza/Src/communicator/target/debug/deps -L dependency=/home/alireza/Src/communicator/target/debug/deps --extern communicator=/home/alireza/Src/communicator/target/debug/deps/libcommunicator-dfc3c2e1752e1b41.rlib (exit code: 101)

What am I doing wrong?


#2

Are you building with Cargo or are you using rustc directly?


#3

I am compiling with cargo build command


#4

This needs to be pub fn.


#5

still no luck.still the same error.


#6

@alirezaes
What content of your Cargo.toml file?


#7
[package]
name = "communicator"
version = "0.1.0"
authors = ["Alireza"]

[dependencies]

#8

@alirezaes

I can not able to reproduce your problem,
can you post archive with your code somewhere?


#9

Right now I am too afraid of it being a silly problem!
but here :


#10

@alirezaes

To fix compilation you just need remove #[cfg(test)] from here:

#[cfg(test)]

pub mod client;

because of with #[cfg(test)] at the top of pub mod client, you client
module compiles only if build tests via cargo test