← thecodex.expert · The Codex Family of Knowledge
Rust

Standard Library

Rust deliberately keeps std smaller than Go's or Python's — no async runtime, no HTTP client — leaving those to crates.io by design, not oversight.

Rust 1.95+ std Last verified:
Where this bites you

env::args() hands back Strings, so it has to assume every argument is valid UTF-8 — and on a platform where an argument isn't, it doesn't return an error you could handle. It panics, from inside the iterator, the moment it reaches the bad argument. A command-line tool that works on every test input can crash on a file name it was handed by the operating system.

Rustargs_bug.rs
use std::env;

let args: Vec<String> = env::args().collect();
println!("Args: {:?}", args);
// run with an argument containing the byte 0xFF:
// thread 'main' panicked at library/std/src/env.rs:
// called `Result::unwrap()` on an `Err` value: "\xFF"
Canonical Definition

std covers the fundamentals: collections (Vec, HashMap, already covered), string handling, file and network IO, environment and process interaction, and synchronization primitives. Unlike Go's batteries-included philosophy, Rust deliberately keeps std smaller — there is no built-in async runtime, HTTP client, or JSON parser — leaving those to well-established crates.io packages (Tokio, reqwest, serde) instead, so std can stay stable and small while the ecosystem iterates faster around it.

File and console IO

std::fs covers reading and writing files; std::io provides the Read/Write traits and buffered wrappers that most of std's IO types implement, similar in spirit to Go's io.Reader/io.Writer.

Rustfile_io.rs
use std::fs;

let contents = fs::read_to_string("config.txt")?;
fs::write("output.txt", "hello")?;

use std::io::{self, Write};
print!("Enter name: ");
io::stdout().flush()?;   // ensure the prompt shows before reading input

Environment and process

std::env reads command-line arguments and environment variables; std::process spawns and manages child processes.

Rustenv_process.rs
use std::env;

let args: Vec<String> = env::args().collect();
let port = env::var("PORT").unwrap_or_else(|_| String::from("8080"));

println!("Args: {:?}, Port: {}", args, port);

The page's example is right for ordinary text. When the arguments are file paths or anything else the OS controls, env::args_os() yields OsStrings instead — no UTF-8 promise, so nothing to panic on; convert with to_str() or to_string_lossy() only where you can decide what a bad value should do:

Rustargs_fix.rs
use std::env;

let args: Vec<_> = env::args_os().collect();
println!("Args: {:?}", args);
// Args: ["./args_fix", "hello", "\xFF"]   (no panic)

What's deliberately NOT in std

No async runtime (use Tokio), no HTTP client (use reqwest), no JSON/YAML parsing (use serde with serde_json/serde_yaml), no regular expressions (use the regex crate), and no logging at all — not even a facade. The closest thing, the log crate that defines the log::info!/warn!/error! macros most other logging crates implement against, is itself a crates.io dependency (albeit one maintained by the Rust project), not part of std; you pair it with a separate implementation crate like env_logger or tracing to actually emit anything. This is a deliberate design choice, not a gap — it lets these areas evolve at the pace of the ecosystem rather than being locked to Rust's own release cadence.

Sources

1
The Rust Project. The Rust Standard Library documentation, doc.rust-lang.org/std.