rust external command

use std::process::Command; fn main() { let mut list_dir = Command::new("ls"); list_dir.status().expect("process failed to execute"); println!(); } Cargo.lock Cargo.toml src target

August 2, 2025 · 1 min · Kristian Alexander P

rust fib

fn fib(x: i32) -> i32 { match x { 0 => 0, 1 => 1, _ => fib(x -1) + fib(x -2), } } fn main() { for a in 0..=10 { println!("fib {} is: {}", a, fib(a)) } } fib 0 is: 0 fib 1 is: 1 fib 2 is: 1 fib 3 is: 2 fib 4 is: 3 fib 5 is: 5 fib 6 is: 8 fib 7 is: 13 fib 8 is: 21 fib 9 is: 34 fib 10 is: 55 use std::collections::HashMap; fn memoized_fib(n: u64, memo: &mut HashMap<u64, u64>) -> u64 { if memo.contains_key(&n) { return *memo.get(&n).unwrap(); } let result = match n { 0 => 0, 1 => 1, _ => memoized_fib(n - 1, memo) + memoized_fib(n - 2, memo), }; memo.insert(n, result); result } fn main() { let mut memo: HashMap<u64, u64> = HashMap::new(); for x in 0..=20 { println!("fib ({}): {}", x, memoized_fib(x, &mut memo)); } } fib (0): 0 fib (1): 1 fib (2): 1 fib (3): 2 fib (4): 3 fib (5): 5 fib (6): 8 fib (7): 13 fib (8): 21 fib (9): 34 fib (10): 55 fib (11): 89 fib (12): 144 fib (13): 233 fib (14): 377 fib (15): 610 fib (16): 987 fib (17): 1597 fib (18): 2584 fib (19): 4181 fib (20): 6765

August 2, 2025 · 2 min · Kristian Alexander P

fd

fd is a program written in Rust to find entries in your filesystem. It is a simple, fast and user-friendly alternative to find. While it does not aim to support all of find’s powerful functionality, it provides sensible (opinionated) defaults for a majority of use cases.

August 1, 2025 · 1 min · Kristian Alexander P

ripgrep

ripgrep is a line-oriented search tool written in Rust, that recursively searches the current directory for a regex pattern. By default, ripgrep will respect gitignore rules and automatically skip hidden files/directories and binary files. (To disable all automatic filtering by default, use rg -uuu.) ripgrep has first class support on Windows, macOS and Linux, with binary downloads available for every release. ripgrep is similar to other popular search tools like The Silver Searcher, ack and grep. ...

August 1, 2025 · 1 min · Kristian Alexander P

rust cargo

Cargo Cargo is the Rust package manager. Cargo downloads your Rust package’s dependencies, compiles your packages, makes distributable packages, and uploads them to crates.io, the Rust community’s package registry. You can contribute to this book on GitHub.

August 1, 2025 · 1 min · Kristian Alexander P

rust common collection

Common Collection Rust’s standard library includes a number of very useful data structures called collections. Most other data types represent one specific value, but collections can contain multiple values. Unlike the built-in array and tuple types, the data that these collections point to is stored on the heap, which means the amount of data does not need to be known at compile time and can grow or shrink as the program runs. Each kind of collection has different capabilities and costs, and choosing an appropriate one for your current situation is a skill you’ll develop over time. ...

August 1, 2025 · 2 min · Kristian Alexander P

Rust Comments

Comments All programmers strive to make their code easy to understand, but sometimes extra explanation is warranted. In these cases, programmers leave comments in their source code that the compiler will ignore but people reading the source code may find useful. // hello, world In Rust, the idiomatic comment style starts a comment with two slashes, and the comment continues until the end of the line. For comments that extend beyond a single line, you’ll need to include // on each line, like this: ...

July 31, 2025 · 1 min · Kristian Alexander P

Rust Control Flow

Control Flow The ability to run some code depending on whether a condition is true and to run some code repeatedly while a condition is true are basic building blocks in most programming languages. The most common constructs that let you control the flow of execution of Rust code are if expressions and loops.

July 31, 2025 · 1 min · Kristian Alexander P

Rust Enums

Defining Enum Where structs give you a way of grouping together related fields and data, like a Rectangle with its width and height, enums give you a way of saying a value is one of a possible set of values. For example, we may want to say that Rectangle is one of a set of possible shapes that also includes Circle and Triangle. To do this, Rust allows us to encode these possibilities as an enum. ...

July 31, 2025 · 5 min · Kristian Alexander P

Rust Functions

Functions Functions are prevalent in Rust code. You’ve already seen one of the most important functions in the language: the main function, which is the entry point of many programs. You’ve also seen the fn keyword, which allows you to declare new functions. Rust code uses snake case as the conventional style for function and variable names, in which all letters are lowercase and underscores separate words. Here’s a program that contains an example function definition: ...

July 31, 2025 · 1 min · Kristian Alexander P