Relationship of Rust function functions, Introduction to packages and modules I. Relationship between function functions
As you can see earlier, multiple function functions can be defined in a file, and these function functions may be used by each other. The entrance to the program is main ().
In a file, the definition and use of each function function are not constrained by the order defined by the function function. That is, there is no need to have a declaration statement, like in C, before a function is used and a function is not defined, and as in Java, as long as a function function is declared within a file, the order in which the function functions appear in the file can be ignored.
II. Package Management of documents
When there are more and more function functions in a file, reading and modifying are a problem. Therefore, functional separation is required, and function functions are saved in separate files according to the operation or function.
In addition, from the perspective of software engineering to consider the reuse and encapsulation of software, some functions need to be set to external access to public, and some are designed for internal use only private.
The Rust project's package management uses the term crate, which is equivalent to the packages in Java.
Cargo is a built-in package management tool for rust.
A crate can be a rust program that can be run, or it can be a library repository for functional functions (like Android's project to differentiate between running apps and Lib).
In addition to crate, Rust also provides a mechanism for module modules. Multiple module modules can be included in each crate, one of which is assumed to be (root module) root modules. The root module and other modules form a tree structure, just like the relationship between the root element in an XML file and the other child elements, or the relationships of multiple subfolders contained in a folder.
Before you do the module and combat operations, introduce Rust's project management tools: Cargo, which has been used in previous articles, like the Maven tools in Java, for project creation, compilation, running, packaging, deployment, and dependencies between packages, dependent on automatic download and update of packages.
Introduction to the relationships, packages, and modules of Rust function functions