Rust's module system, pub, and re-exports.


Module Structure

src/
├── main.rs
└── exchanges/
    ├── mod.rs
    └── binance/
        ├── mod.rs
        └── client.rs

Exporting at Each Level

exchanges/binance/[mod.rs](<http://mod.rs>)

mod client;
pub use client::BinanceClient;  // Re-export

exchanges/[mod.rs](<http://mod.rs>)

pub mod binance;
pub use binance::BinanceClient;  // Re-export again

main.rs

mod exchanges;
use exchanges::BinanceClient;  // Now works!

Without Re-export

use exchanges::binance::BinanceClient;  // Full path, still works

Struct vs Field Visibility

They are separate!

pub struct User {    // Struct is public
    id: u64,         // Field is PRIVATE (default)
    pub name: String,  // Field is PUBLIC
}
pub on... Who can see it
struct only Type visible everywhere, fields only in same module
struct + field Type and that field visible everywhere
Neither Only visible within same module

Same Module = Full Access

// src/models/user.rs
pub struct User {
    id: u64,  // No pub
}

impl User {
    pub fn get_id(&self) -> u64 {
        self.id  // ✓ Works—same module
    }
}