"Pub Restricted" not documented

#1

I’ve been writing Rust in my spare time for a while now, and I’ve read the Rust Book and have done my battles with the borrow checker.

Despite all that I haven’t heard about the restricting features of the pub keyword. I just found out because it was used in a blog post without comment.
Specifically I’m talking about this feature: https://github.com/rust-lang/rfcs/blob/master/text/1422-pub-restricted.md

Why isn’t this feature documented in the book?

Are there other undocumented / not easily discoverable features that I haven’t heard of?

Relevant chapter of the book: https://doc.rust-lang.org/stable/book/ch07-02-modules-and-use-to-control-scope-and-privacy.html

0 Likes

#2

Hi, you can find this feature here in the reference.
The book doesn’t cover everything, I think it’s because as a beginner if I link you the book and it’s 500 pages long, you won’t even want to start reading it. The book has to show you what Rust can do and how but not necessarily in depth, so it will teach you some features only partially, like the pub keyword but not it’s more complicated forms.
If you want to know more about the language, there is the reference trying to explain everything in the language, the rustonomicon explaining advanced features and unsafe, the unstable book for unstable features and the rustc guide explaining how the compiler works. They are all listed on the main doc page, https://doc.rust-lang.org/.
If you want to be really up-to-date, I suggest reading the recent release notes you can find them here.

3 Likes

#3

I guess I’m a victim of my own assumption that the rustonomicon was about code that was “advanced and unsafe” and not “advanced code” and “unsafe code”. Which led me to ignore it, since I don’t want to write any unsafe code at all.

I do follow the release notes somewhat, but that doesn’t help me with earlier introduced advanced features.
Conclusion: I should read the rustonomicon. Thanks! :slight_smile:

2 Likes

#4

Yes, exactly: in fact it’s 552 pages long!! We unfortunately can’t cover absolutely everything; we try to cover the most common Rust features :slight_smile:

0 Likes

#5

I’d recommend checking these sorts of things out. Even if you don’t plan to use unsafe code in your everyday work, understanding how unsafe code is written gives you a better understanding of the tools you’re using (e.g. did you know BTreeMap is one of the biggest chunks of unsafe code in the standard library?).

2 Likes