Using module from by doing use crate::module

I'm trying to use, in, pub functions defined in



use crate::parser_utilities::{parse_c_seq, parse_session};

pub mod parser_utilities;

pub fn parse_c_seq...
pub fn parse_session...


 --> src/
2 | use crate::parser_utilities::{parse_c_seq, parse_session};
  |            ^^^^^^^^^^^^^^^^
  |            |
  |            unresolved import
  |            help: a similar path exists: `rtsp_client::parser_utilities`

I then try:

use rtsp_client::parser_utilities::{parse_c_seq, parse_session};

error[E0433]: failed to resolve: use of undeclared crate or module `rtsp_client`
 --> src/
2 | use rtsp_client::parser_utilities::{parse_c_seq, parse_session};
  |     ^^^^^^^^^^^ use of undeclared crate or module `rtsp_client`

but my crate is called rtsp_client

I also tried crate::rtsp_client::parser_utilities

What is wrong? I should be able to access any pub module from using use crate mod_name;

Is a module within your library crate, or is it part of a binary crate? That is, are you including it with "mod client;" inside of, or are you building it in some other way (for example, by listing it as a binary in Cargo.toml, or including it as a module in a binary crate like

If these files are all part of the same library, then you should have the following code in

pub mod client; // remove `pub` if this is internal to your library

and everywhere else that uses the client module can refer to it as crate::client (within your library crate) or rtsp_client::client (within other crates). You should have only one "mod client;" line in your entire project.

If is built as a binary crate, then it should not be included as a module in your library, and it should refer to code from your library crate with paths like rtsp_client::parser_utils. does have pub mod client and is not an executable, however I get the error still

somehow, adding

mod parser_utilities;

made compile. Why?

Can you share your Cargo.toml?

name = "rtsp_client"
version = "0.1.0"
edition = "2018"

rtsp-types = { path = "./rtsp-types" }
sdp-types = { path = "./sdp-types" }
futures = "0.3.13"
log = "0.4.14"
rand = "0.8.3"

I had to add mod parser_utilities; in for it to work, which is very strange

Ah, so you have both and These are built as two separate crates: is the root module of your library crate, and is the root module of your binary crate.

You should declare each sub-module in just one of these two crates. For example, if they are both declared in your library crate:

pub mod parser_utilities;
pub mod client;

Then anywhere within the library crate, you can access them under the crate:: namespace, since they are part of the same crate:

use crate::parser_utilities::{parse_c_seq, parse_session};

And within the binary crate, you can access them through the rtsp_client library. You can "use" paths from your library crate in order to import their names, but do not use "mod" here if your library already declared this module.

use rtsp_client::client;
use rtsp_client::parser_utilities::parse_session;