- 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.
- R語言數據分析從入門到精通
- Android應用程序開發與典型案例
- 單片機C語言程序設計實訓100例:基于STC8051+Proteus仿真與實戰
- MATLAB圖像處理超級學習手冊
- Java Web基礎與實例教程(第2版·微課版)
- jQuery EasyUI網站開發實戰
- WSO2 Developer’s Guide
- Python高級編程
- C++程序設計基礎教程
- SharePoint Development with the SharePoint Framework
- GameMaker Essentials
- QGIS 2 Cookbook
- 零基礎學Scratch 3.0編程
- Learning Android Application Testing
- SwiftUI極簡開發