Rust access control: Difference between revisions
From wikinotes
(Created page with "By default in rust, everything is private (current module access only). = Documentation = {| | visibility and privacy || https://doc.rust-lang.org/reference/visibility-and-privacy.html |} = Objects = <blockquote> * Objects are private by default. * A private object instance cannot be returned to a different module. * A public struct with private fields cannot be instantiated outside of it's module. </blockquote><!-- objects --> = Modules = <blockquote> * Modules are...") |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 17: | Line 17: | ||
= Modules = | = Modules = | ||
<blockquote> | <blockquote> | ||
* Modules are private by default | * Modules are private by default, but can be published by their parent module | ||
* Parent modules are not visible to their children by default, but can be accessed with <code>super</code> or with absolute paths from <code>crate::</code> | |||
* Modules are implied by the filename, you can however create a submodule within a file using <code>mod ${your_module}</code> | * Modules are implied by the filename, you can however create a submodule within a file using <code>mod ${your_module}</code> | ||
</blockquote><!-- modules --> | </blockquote><!-- modules --> |
Latest revision as of 15:50, 8 February 2023
By default in rust, everything is private (current module access only).
Documentation
visibility and privacy | https://doc.rust-lang.org/reference/visibility-and-privacy.html |
Objects
- Objects are private by default.
- A private object instance cannot be returned to a different module.
- A public struct with private fields cannot be instantiated outside of it's module.
Modules
- Modules are private by default, but can be published by their parent module
- Parent modules are not visible to their children by default, but can be accessed with
super
or with absolute paths fromcrate::
- Modules are implied by the filename, you can however create a submodule within a file using
mod ${your_module}