Re-exporting private modules

Currently, it's not possible to re-export private modules. This code is not valid

fn main() {
    let hello = file::iMod::Hello {
        name: String::from("Omar")
    };
    dbg!(hello);
}

mod file {
    mod myMod {
        #[derive(Debug)]
        pub struct Hello {
            pub name: String,
        }
    }
    pub use myMod as iMod;
}

However, it's still possible to export the Hello struct

fn main() {
    let hello = file::iHello {
        name: String::from("Omar")
    };
    dbg!(hello);
}

mod file {
    mod myMod {
        #[derive(Debug)]
        pub struct Hello {
            pub name: String,
        }
    }
    pub use myMod::Hello as iHello;
}

Since you can export everything inside myMod, I think it makes sense to make it possible to re-export private modules?

Use Case: Some libraries generate modules with Derive. I would like to use these modules and the structs inside them in other parts of the code. It's not possible to add the pub keyword since this code is auto-generated (or is it?).

Ypu can still "re-export" these modules by using a glob use to re-export all of it's items.

mod file {
    mod myMod {
        #[derive(Debug)]
        pub struct Hello {
            pub name: String,
        }
    }
    // like this 
    pub mod iHello {
        pub use myMod::Hello::*;
    }
}

Thank you!

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.