YouTip LogoYouTip

Rust Project Management

Any programming language that cannot organize code is difficult to go deep into, and almost no software product is compiled from a single source file. All programs in this tutorial so far have been written in a single file, mainly to facilitate learning Rust's syntax and concepts. For a project, organizing code is very important. There are three important organizational concepts in Rust: Crate, Package, and Module. ### Crate "A crate" is a binary program file or library file, which exists in a "package". Crates have a tree-like structure, and its root is the program compiled from the source file that the compiler starts with when running. Note: "Binary program file" is not necessarily "binary executable file", it can only be confirmed as a file containing target machine language, and the file format varies depending on the compilation environment. ### Package When we use Cargo's new command to create a Rust project, a Cargo.toml file will be created in the project directory. The essence of a project is a package, which must be managed by a Cargo.toml file that describes the package's basic information and dependencies. A package can contain at most one library crate, and can contain any number of binary crates, but must contain at least one crate (whether library or binary). When a package is created using the cargo new command, a main.rs source file will be generated in the src directory. Cargo defaults this file as the root of the binary crate, and the compiled binary crate will have the same name as the package. ### Module For a software project, we often organize according to the organizational norms of the programming language being used. The main structure of organizing modules is often a tree. Java organizes functional modules mainly by class, while JavaScript organizes modules mainly by function. These advanced language organizational units can be nested layer upon layer, just like the directory structure of a file system. The organizational unit in Rust is the Module (Module).
← Rust GenericsRust Struct β†’