Using module from lib.rs by doing use crate::module

I'm trying to use, in client.rs, pub functions defined in parser_utilities.rs

project:

src/client.rs
src/lib.rs
src/parser_utilities.rs

client.rs:

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

lib.rs:

pub mod parser_utilities;

parser_utilities.rs:

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

Error:

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

I then try:

client.rs:

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

error[E0433]: failed to resolve: use of undeclared crate or module `rtsp_client`
 --> src/client.rs:2:5
  |
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 lib.rs using use crate mod_name;

Is client.rs 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 lib.rs, 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 main.rs)?

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

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 client.rs 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.

lib.rs does have pub mod client and client.rs is not an executable, however I get the error still

somehow, adding

mod parser_utilities;

made client.rs compile. Why?

Can you share your Cargo.toml?

[package]
name = "rtsp_client"
version = "0.1.0"
edition = "2018"

[dependencies]
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 main.rs for it to work, which is very strange

Ah, so you have both lib.rs and main.rs. These are built as two separate crates: lib.rs is the root module of your library crate, and main.rs 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:

// lib.rs
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:

// client.rs
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.

// main.rs
use rtsp_client::client;
use rtsp_client::parser_utilities::parse_session;