How to reduce the number of "use" when splitting a file

I have a file like this.

pub mod get_mod{
    use crate::getfunc;

    pub fn get_a (){
    pub fn get_b (){

I'd like to split such a file by function, but I would need a use for each file.
Is there a way to reduce or eliminate the number of use?

You can use super::*; to bring all names in scope from the parent module into scope for the child module. You could also define a macro which expands to some use statements, or define a prelude module which you glob import from.

Generally, though, it's standard practice to just use what you need in the module that you need it.


general style doesn't go so drastic; it's normal to keep related functionality defined in a single file. This example is probably just an oversimplification for the purpose of posting on the forum, but it merits stating.


thank you.
I was using super without knowing much about it, but it seems to work as expected.

pub mod get_mod{
    use crate::getfunc;

    pub mod get_a;

use super::getfunc;

pub fn get_(){
    let a = getfunc::get_a();
    println!("{}", a);

Yes, that's what I intend to do.
Import only common crates with super.

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.