Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

async-coap-uri: fix imports #27

Open
Luro02 opened this issue Apr 3, 2020 · 2 comments
Open

async-coap-uri: fix imports #27

Luro02 opened this issue Apr 3, 2020 · 2 comments
Labels
cleanup P2 Priority 2

Comments

@Luro02
Copy link
Contributor

Luro02 commented Apr 3, 2020

Almost all modules have wildcard imports

use super::*;

which I would consider bad practice, because it is harder to see which files/modules a file depends on.

It could also cause unexpected overwrites of imports, if one is not careful about it.

For example:

file.rs

pub struct Wrapper(usize);

impl Wrapper {
    pub fn new() -> Self {
        Self(1)
    }
}

other.rs

pub struct Wrapper(usize);

impl Wrapper {
    pub fn new() -> Self {
        Self(2)
    }
}

lib.rs

mod file;
mod other;

use file::*;
use other::*;

third.rs

use super::*;

pub fn hello() {
    // this would print `wrapper: 2`, because other::Wrapper overwrites file::Wrapper
    println!("wrapper: {}", Wrapper::new());
}

but if one removes the other::Wrapper the behavior of third::hello would change without anyone noticing.

@darconeous
Copy link
Contributor

I tend to use vi a lot for editing, and it's not really great at auto-importing. Using super::* in-crate thus saves me a lot of time.

Yes, it appears you can create logically ambiguous name resolutions that the compiler thinks are unambiguous, which is undesirable. In practice this is rarely a problem, at least in my experience. It's hard to imagine such a thing not causing a compiler error, and it's easily fixed with a few more use statements.

All that being said, now that this project is more fleshed out I'm not opposed to doing away with the use super::*; and importing everything explicitly. It would be nice if there was an automated way to do this.

@darconeous darconeous added cleanup P2 Priority 2 labels Apr 11, 2020
@Luro02
Copy link
Contributor Author

Luro02 commented Apr 12, 2020

I am working on this :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cleanup P2 Priority 2
Projects
None yet
Development

No branches or pull requests

2 participants