Confused on mod, use, pub. Simple example


I’ve reduced my program down to these 5 example files. What declarations do I need to add to module “funny” so that compiles as-is?

mod funny;
use funny::{Funny, funny_a, funny_b};

fn main()


pub struct Funny;

mod imports; // Must not be exposed to user
pub mod a;
pub mod b;

// [#1] what to put here


// [#2] what to put here

pub fn funny_a(val: u32) -> Funny


// [#3] what to put here

pub fn funny_b(val: u32) -> Funny


/* I want FFI imports in a separate file because they
are a mile long and shared by "" / "" */

pub const HAPPY_VALUE: u32 = 7;
pub const SAD_VALUE: u32 = 13;

pub use self::a::funny_a;
pub use self::b::funny_b;
use funny::b::funny_b;
use funny::import::HAPPY_VALUE;
use funny::a::funny_a;
use funny::import::SAD_VALUE;


Nope :confused:

Module a calls module b and vice-versa. That’s where my hangup is.


Edited. Sorry; missed that.


Awesome, that finally works, thank you!

Out of curiosity, why can’t I use a wildcard to just bring in everything from the “imports” module? (like the following)


use funny::Funny;
use funny::a::funny_a;
use funny::imports::*;

pub fn funny_b(val: u32) -> Funny

The documentation seems to state this should be possible.


Well, you can… it’s just bad form. If you use a wildcard, it makes it harder to work out where any given symbol has come from.

About the only times I use a wildcard is when I’m re-exporting exactly one module (so it’s unambiguous), or I’m writing an enum member function that just matches on itself.


Ahhh okay that makes sense.

It actually does give a compiler error though to use a wildcard there.

Thanks for your help.


I should probably mention that wildcards are also buggy and sometimes freak out, especially in the presence of cyclic imports.