Rust Search

Find the best content on Rust, curated by the community; a search engine for Rustaceans.
doc.rust-lang.org
Testing Rust is a programming language that cares a lot about correctness and it includes support for writing software tests within the language itself. Testing comes in three styles: • Unit testing. • Doc testing. • Integration testing. Al...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Foreign Function Interface Rust provides a Foreign Function Interface (FFI) to C libraries. Foreign functions must be declared inside an extern block annotated with a #[link] attribute containing the name of the foreign library. use std::fm...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Argument parsing Matching can be used to parse simple arguments: use std::env; fn increase(number: i32) { println!("{}", number + 1); } fn decrease(number: i32) { println!("{}", number - 1); } fn help() { println!("usage: match_args <string...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Program arguments Standard Library The command line arguments can be accessed using std::env::args, which returns an iterator that yields a String for each argument: use std::env; fn main() { let args: Vec<String> = env::args().collect(); /...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Filesystem Operations The std::fs module contains several functions that deal with the filesystem. use std::fs; use std::fs::{File, OpenOptions}; use std::io; use std::io::prelude::*; #[cfg(target_family = "unix")] use std::os::unix; #[cfg(...
Rust by Example Book 2024-01-01 ~2 min read
doc.rust-lang.org
Wait If you'd like to wait for a process::Child to finish, you must call Child::wait, which will return a process::ExitStatus. use std::process::Command; fn main() { let mut child = Command::new("sleep").arg("5").spawn().unwrap(); let _resu...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Pipes The std::process::Child struct represents a child process, and exposes the stdin, stdout and stderr handles for interaction with the underlying process via pipes. use std::io::prelude::*; use std::process::{Command, Stdio}; static PAN...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Child processes The process::Output struct represents the output of a finished child process, and the process::Command struct is a process builder. use std::process::Command; fn main() { let output = Command::new("rustc") .arg("--version")...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
read_lines A naive approach This might be a reasonable first attempt for a beginner's first implementation for reading lines from a file. use std::fs::read_to_string; fn read_lines(filename: &str) -> Vec<String> { let mut result = Vec::new(...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
create The create function opens a file in write-only mode. If the file already existed, the old content is destroyed. Otherwise, a new file is created. static LOREM_IPSUM: &str = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, s...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
open The open function can be used to open a file in read-only mode. A File owns a resource, the file descriptor and takes care of closing the file when it is droped. use std::fs::File; use std::io::prelude::*; use std::path::Path; fn main(...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
File I/O The File struct represents a file that has been opened (it wraps a file descriptor), and gives read and/or write access to the underlying file. Since many things can go wrong when doing file I/O, all the File methods return the io:...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Path The Path type represents file paths in the underlying filesystem. Across all platforms there is a single std::path::Path that abstracts over platform-specific path semantics and separators. Bring it into scope with use std::path::Path;...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Channels Rust provides asynchronous channels for communication between threads. Channels allow a unidirectional flow of information between two end-points: the Sender and the Receiver. use std::sync::mpsc::{Sender, Receiver}; use std::sync:...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Testcase: map-reduce Rust makes it very easy to parallelize data processing, without many of the headaches traditionally associated with such an attempt. The standard library provides great threading primitives out of the box. These, combin...
Rust by Example Book 2024-01-01 ~3 min read
doc.rust-lang.org
Threads Rust provides a mechanism for spawning native OS threads via the spawn function, the argument of this function is a moving closure. use std::thread; const NTHREADS: u32 = 10; // This is the `main` thread fn main() { // Make a vector...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Std misc Many other types are provided by the std library to support things such as: • Threads • Channels • File I/O These expand beyond what the primitives provide. See also: primitives and the std library
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Arc
Arc When shared ownership between threads is needed, Arc(Atomically Reference Counted) can be used. This struct, via the Clone implementation can create a reference pointer for the location of a value in the memory heap while increasing the...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
Rc
Rc When multiple ownership is needed, Rc(Reference Counting) can be used. Rc keeps track of the number of the references which means the number of owners of the value wrapped inside an Rc. Reference count of an Rc increases by 1 whenever an...
Rust by Example Book 2024-01-01 ~1 min read
doc.rust-lang.org
HashSet Consider a HashSet as a HashMap where we just care about the keys ( HashSet<T> is, in actuality, just a wrapper around HashMap<T, ()>). "What's the point of that?" you ask. "I could just store the keys in a Vec." A HashSet's unique...
Rust by Example Book 2024-01-01 ~1 min read
"Writing rust for me is a gradual process of the compiler patiently guiding me towards the program I should have written in the first place, and at the..."

Search tips

Type anything to search across articles, videos (including conference talks), podcasts, research, crates, and Rust API documentation. These operators give you finer control — click an example to try it.

Find pages containing all your words. Pages where the words appear together rank higher.
Quote part of your query to keep those words together as an exact phrase within a larger search.
Wrap the whole query in quotes for a verbatim search that matches text exactly, punctuation and all — perfect for Rust syntax. Needs at least 3 characters.
Put ! first to open the top result immediately. Quote the whole query for a literal leading bang, as in '!Send'. Bangs elsewhere, such as println!, stay literal. Browser and launcher shortcuts can invoke this directly. See search integrations.
Limit results to a single site. Works on its own () too. One site: per search.

Use the tabs and filters above the results to narrow by content type, publication year, and sort order.