- Rust Quick Start Guide
- Daniel Arbuckle
- 222字
- 2021-06-10 19:46:04
Public and private module items
In many of the preceding examples, we saw a pub keyword. That keyword makes the item it's attached to public, meaning that it is available to code that is not part of the same module. If we omit the pub keyword on an item, that item is private, meaning that it can only be accessed within the module where it is defined. Private is the default, so we need to explicitly mark those items that we want to have as part of the module's externally accessible interface as public by using the pub keyword.
Making an item private is not a security mechanism. If you're worried that your code will be linked with hostile code that might misuse your code or data, making the code or data private will not protect against such attacks. Rather, the distinction between public and private exists in order to help us make it plain which parts of the code are intended for use outside of the current module, and which are meant to be used only internally. This helps us maintain our software, because we are free to make whatever changes we want to to private items, whereas with public items, we have to be careful that our changes do not break external things we might not even be aware exist.
- Deploying Node.js
- C++程序設計(第3版)
- 國際大學生程序設計競賽中山大學內部選拔真題解(二)
- Spring 5企業級開發實戰
- 自己動手寫搜索引擎
- SOA實踐
- JavaScript語言精髓與編程實踐(第3版)
- NLTK基礎教程:用NLTK和Python庫構建機器學習應用
- Software Testing using Visual Studio 2012
- Servlet/JSP深入詳解
- C語言程序設計案例式教程
- Oracle Database 12c Security Cookbook
- Android 應用案例開發大全(第3版)
- Learning Python by Building Games
- Working with Odoo