Problems with "pub" being ineffective

A module structure problem has me puzzled.

├── messages
│   ├──
│   └──
└── viewer

Layout is per the Rust book.

Error message is:

error[E0603]: struct import `Msgdecode` is private
  --> src/
77 | fn processudppkt(mut decoder: &messages::msgdecode::Msgdecode, pkt: &PacketHeaders)
   |                                                     ^^^^^^^^^ private struct import
note: the struct import `Msgdecode` is defined here...
  --> src/messages/
13 | use crate::messages::Msgdecode;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...and refers to the struct `Msgdecode` which is defined here
  --> src/messages/
18 | pub struct Msgdecode {
   | ^^^^^^^^^^^^^^^^^^^^ consider importing it directly

"" is just a skeleton right now:

pub mod msgdecode;
pub struct Msgdecode {       

Everything is public.

In "", the module is made visible with

use crate::messages;

That's enough that the compiler can find "messsages/" from "", but it insists it's private.

The error hint "Consider importing it directly" let me to try "mod pub messages", but that just led to dead ends like

pub mod crate::messages; // not allowed
pub mod messages; // not found, since it's at the same level in the tree

How do I fix the privacy problem?

You have something like this **in ``**:
mod messages;

That's where you need to add pub.

Never mind, I skimmed the error message and leapt to an incorrect conclusion.

Tried that. No effect, Here are the imports in now:

extern crate simplelog;
extern crate argparse;
use std::fs::File;
use std::collections::HashMap;
use simplelog::{LevelFilter,TermLogger,WriteLogger,Config};

pub mod messages;
mod pcap;

Just added the "pub" to "mod messages", as suggested.

Your struct Msgdecode is defined in the messages module, not in msgdecode, yet you refer to it as messages::msgdecode::Msgdecode

You do not need the pub modifier on pub mod messages; to access it from pcap because messages is a sibling to pcap


If you want it to be available at both paths, then you can change the use to pub use in

pub use crate::messages::Msgdecode;

This will “re-export” the name so that it is visible as crate::messages::msgdecode::Msgdecode as well as at its original path crate::messages::Msgdecode.


Thanks. That works.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.