rust vector

Creating vector in rust. let mut v = Vec::new(); v.push(5); v.push(6); v.push(7); v.push(8); println!("{:?}", v) [5, 6, 7, 8] Reading Elements of Vectors let v = vec![1, 2, 3, 4, 5]; let third: &i32 = &v[2]; println!("The third element is {third}"); let third: Option<&i32> = v.get(2); match third { Some(third) => println!("The third element is {third}"), None => println!("There is no third element."), } println!("{:?}", v) The third element is 3 The third element is 3 [1, 2, 3, 4, 5] Option<T> is an enum that represents the presence or absence of a value. It is a fundamental type in Rust’s approach to handling nullable values and potential errors, promoting explicit handling rather than implicit null pointers found in other languages. ...

July 29, 2025 · 1 min · Kristian Alexander P

perfect-number

What is perfect number? In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3 (excluding itself), and 1 + 2 + 3 = 6, so 6 is a perfect number. The next perfect number is 28, since 1 + 2 + 4 + 7 + 14 = 28. ...

March 14, 2024 · 1 min · Kristian Alexander P

python script examples

Example python scripts archlinux packages import subprocess def packages_list(): """Yay packages list""" packages = subprocess.run(["yay", "-Qu"], capture_output=True, text=True) if packages.stdout: return packages.stdout else: return "all packages updated!" return packages_list() get the wireless interface import subprocess import re def get_wlan_iface(): """Get the wireless interface name.""" interfaces = subprocess.run( ["ip", "link", "show"], capture_output=True, text=True ) pattern = r"(^\d+:\s+)(wl.+):" for iface in interfaces.stdout.splitlines(): if re.search(pattern, iface): match = re.search(pattern, iface) assert match is not None return match.group(2) return get_wlan_iface()

March 14, 2024 · 1 min · Kristian Alexander P

rust hello world

Hello world The basic hello world in Rust. fn main() { // Statements here are executed when the compiled binary is called. // Print text to the console. println!("Hello World!"); } Backlinks rustup

February 25, 2024 · 1 min · Kristian Alexander P

rustup

Install rust Get the installer script here for linux, but also support other os’es like windows. In archlinux, using rustup is the recommended way to install if you intend to program anything in Rust.

February 25, 2024 · 1 min · Kristian Alexander P