You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can refer to modules in the same crate in different ways. For example, given a crate like this:
src/
lib.rs
a.rs
b.rs
a can import trait B in b as crate::b::B or super::b::B. And if B is pub use in lib.rs, a can also refer B as crate::B. All these work, but it is troublesome to think about which way to go every time. So I think it will be better if we have a guideline about this.
My opinion is that we should prefer referring things relatively using super::b::B because:
It doesn't assume if B is public or not
When refactoring file structure, for example, if we want to move a.rs and b.rs to a sub-directory, the code still works
@huachaohuang fine. If B is not public, the compiler will complain. For refactor purposes, the compiler will also help in spotting, and refactor tools will help.
I'll keep this issue open for a while to further comments if any.
Thanks for reaching out but I'm going to close this as it's not really the type of thing we can codify in this guideline which is really geared to how the code the developer wrote should be styled/formatted (as opposed to analyzing the entirety of the crate to provide guidance on what the developer should have written.
We can refer to modules in the same crate in different ways. For example, given a crate like this:
a
can import traitB
inb
ascrate::b::B
orsuper::b::B
. And ifB
ispub use
inlib.rs
,a
can also referB
ascrate::B
. All these work, but it is troublesome to think about which way to go every time. So I think it will be better if we have a guideline about this.My opinion is that we should prefer referring things relatively using
super::b::B
because:B
is public or nota.rs
andb.rs
to a sub-directory, the code still worksOriginally posted by @huachaohuang in rust-lang/api-guidelines#255
The text was updated successfully, but these errors were encountered: