-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a description of pub restricted #548
Conversation
module/pub-restricted.md
Outdated
|
||
这段代码编译无法通过,因为 `J` 无法在 `mod c` 的外部访问,而 `fn semisecret` 尝试在 `mod a` 中访问 `J`. | ||
|
||
在 rust1.18 之前,正确的写法是,将 `fn semisecret` 移动到 `mod c` 中,并将其 `pub`,之后根据需要可以重新导出 `semisecret`。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
正确的做法难道不是在 mod a
里 use self::b::c::J;
么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在 mod a
中 use self::b::c::J
是不行的,会被编译器拒绝,http://play.integer32.com/?gist=0257ccea97fb26a26c52ebf1ed0970f6&version=stable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当然。你需要设置 J 为 pub吧。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
实际上,需要 mod c
和 J
同时设为 pub,或者 pub J
同时在 b
中 pub use self::c::J;
module/pub-restricted.md
Outdated
} | ||
``` | ||
|
||
这种情况可以正常工作,但是,这里有个严重的问题:无法明确的说明 `fn semiseret` 是为什么要 `pub`。同时,如果在 `a` 中使用 `pub use self::b::semisecret` ,那么所有人都可以通过 `use` 访问 `fn semiseret`,但是实际上,这个函数只需要让 `mod a` 访问就可以了。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没弄懂。。。这种情况下不用 pub use
来 re-export 不好么。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看了下面明白了,这里应该是 mod c
需要限制 mod a
的 re-export
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段,我翻译的有点问题,句子不知道应该怎么翻译了,这是原文
This works, but there is a serious issue with it: One cannot easily tell exactly how "public" fn semisecret is. In particular, understanding who can access semisecret requires reasoning about (1.) all of the pub use's (aka re-exports) of semisecret, and (2.) the pub-ness of every module in a path leading to fn semisecret or one of its re-exports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nimenzaishuoshemme
@wayslog 改了一点用词,你看看? |
关于 pub(restricted) 的简单描述