In Rust, the standard library provides a core set of features to help developers perform common programming tasks. When using these features, we need to reference them through specific module paths. Below, we will introduce the structure of the Rust standard library in detail and provide the correspondinguse
path.
Rust Standard Library Module Path
1. Core primitive type
Basic numeric types, boolean types, characters and string slices, etc. usually do not require additionaluse
statements, because they are a basic component of the Rust language.
2. Collection Type
vector(Vec<T>
)
use std::vec::Vec;
String (String
)
// It usually does not require explicit import String,Because it's in prelude middle
Hash mapping (HashMap<K, V>
) and hash collections (HashSet<T>
)
use std::collections::HashMap; use std::collections::HashSet;
Binary heap (BinaryHeap<T>
)
use std::collections::BinaryHeap;
3. Error handling
Result<T, E>
andOption<T>
// These two types usually do not require explicit import,Because they are prelude middle
4. I/O operations and file systems
Read and write files
use std::fs::File; use std::io::Read; use std::io::Write;
Buffer
use std::io::BufReader; use std::io::BufWriter;
Standard input/output/Error stream
use std::io::{self, stdin, stdout, stderr};
Path operation
use std::path::{Path, PathBuf};
5. Concurrent and asynchronous programming
Thread
use std::thread;
Mutex and read and write locks
use std::sync::Mutex; use std::sync::RwLock;
Conditional variables
use std::sync::Condvar;
Atomic Type
use std::sync::atomic::{AtomicUsize, Ordering}; // Import other atomic types as needed,like AtomicBool, AtomicIsize wait
6. Network (basic functions, advanced functions are usually in external libraries)
TCP/UDP
use std::net::{TcpListener, TcpStream, UdpSocket};
7. Other practical functions
Time processing
use std::time::{Duration, Instant, SystemTime};
Random number generation
// The standard library does not contain random number generators, and external libraries such as rand are usually used.
Environment variable processing
use std::env;
Command line parameter analysis
use std::env::args;
Please note that as Rust develops, the specific structure of the standard library anduse
The path may change. To obtain the most accurate information, it is recommended to consult Rust's official documentation or use Rust's document generation toolrustdoc
。
Additionally, while the Rust standard library provides many core features, developers often rely on rich third-party libraries and frameworks for more complex or specific tasks (such as advanced network programming, web development, GUI development, etc.). These libraries and frameworks can be accessed through Rust's package managercargo
Easily add to your project.
Standard library path overview
The following is the Rust Standard Library module path tree compiled based on the above content (only the modules and types mentioned above are listed):
std ├── collections │ ├── HashMap │ ├── HashSet │ └── BinaryHeap ├── fs │ └── File ├── io │ ├── Read │ ├── Write │ ├── stdin │ ├── stdout │ ├── stderr │ ├── BufReader │ ├── BufWriter │ └── net │ ├── TcpListener │ ├── TcpStream │ └── UdpSocket ├── path │ ├── Path │ └── PathBuf ├── sync │ ├── Mutex │ ├── RwLock │ ├── Condvar │ └── atomic │ ├── AtomicUsize │ ├── Ordering │ └── ... (Other atomic types) ├── thread ├── time │ ├── Duration │ ├── Instant │ └── SystemTime ├── env │ └── args └── ... (Other standard library modules and types not listed)
Note that this path tree is a simplified representation and does not contain all modules and types from the standard library. Additionally, some modules and types may be in deeper nesting, but for brevity only the directly related paths are shown here.
This path tree can be used as a reference to help you better understand the relationship between the structure and modules of the Rust standard library. However, for the most accurate and up-to-date information, it is recommended to consult Rust's official documentation or use itrustdoc
Tools generate local documents.
This is the end of this article about the structure of the Rust standard library and its module path. For more relevant Rust standard library structure content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!