Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Rust tells me that an import is unused, and then in the very same breath tells me that I should make that import

Here’s the code:

use crate::rooms::room::RoomInterface;

pub mod dogroom {
    pub struct R;

    impl RoomInterface for R {

    }
}

Here’s /rooms/mod.rs:

pub mod room {

    //  Irrelevant stuff
    
    pub trait RoomInterface {
        // stuff
    }

    // stuff

}

Here’s what it tells me:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

I find it quite arcane that I import the very same thing it wants me to import, and yet it doesn’t work.

I’ve tried pretty much all the permutations of the use keyword, and I can’t make it work. What’s going on?

>Solution :

uses are scoped to the module that imports them, not the file they are in.
Move the import into the dogroom module:

pub mod dogroom {
    use crate::rooms::room::RoomInterface;

    pub struct R;

    impl RoomInterface for R {

    }
}

Alternatively, you might want the dogroom module to reuse everything from the parent module:

use crate::rooms::room::RoomInterface;
pub mod dogroom {
    use super::*;

    pub struct R;

    impl RoomInterface for R {

    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading