Prefer super or crate for internal module references #255
huachaohuang
started this conversation in
API Guidelines
Replies: 1 comment 3 replies
-
This makes no difference to the API of a crate so I believe it would be off topic for the API Guidelines. This project is not an all-purpose Rust code style guide. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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 worksBeta Was this translation helpful? Give feedback.
All reactions