kota's memex

https://rust-lang.org

fn main() {
    println!("hello world");
}

meta

cargo

rust naming

rust documentation

rust testing

rust module system

rust guidelines for binary projects

rust type driven development

basic langauge concepts

rust variables

rust scalar types

rust tuple

rust array

rust vectors

rust strings

rust slices

rust struct

rust enums

rust hash maps

rust functions

rust control flow

rust closures

rust iterators

rust match

rust errors

rust macros

rust print

memory control

rust stack and heap

rust ownership

rust smart pointers

rust generics

rust traits

rust lifetimes

concurrency

Many languages are dogmatic about the solutions they offer for handling concurrent problems. For example, Erlang has elegant functionality for message-passing concurrency but has only obscure ways to share state between threads. Supporting only a subset of possible solutions is a reasonable strategy for higher-level languages, because a higher-level language promises benefits from giving up some control to gain abstractions. However, lower-level languages are expected to provide the solution with the best performance in any given situation and have fewer abstractions over the hardware. Therefore, Rust offers a variety of tools for modeling problems in whatever way is appropriate for your situation and requirements.

rust threads

Classic operating system thread management in rust.

rust message passing

Do not communicate by sharing memory; instead, share memory by communicating.

rust shared state concurrency

Okay, but what if we do want to share some state as a little treat?

rust async

Another model for concurrency that allows us to express how operations could be asynchronous in terms of potential pausing points and eventual results.

libraries

guide to popular crates

bevy

rust config

rust log

rust tracing

serde

anyhow

tokio

actix

reqwest

sqlx

testing libraries

rust claims

rust validator

rust fake

rust quickcheck

loop over a directory

use anyhow::*;
use std::{fs, io};

const ACPI_PATH: &str = "/sys/class/backlight/";

fn main() -> Result<()> {
	let mut entries = fs::read_dir(ACPI_PATH)?
		.map(|res| res.map(|entry| entry.path()))
		.collect::<Result<Vec<_>, io::Error>>()?;

	// Exit if no backlights found.
	if entries.is_empty() {
		return Err(anyhow!("No backlights found."));
	}

	// Get brightness and max brightness.
	entries.sort();
	dbg!(entries);
	Ok(())
}

embed a file in the binary

The file is located relative to the current file (similarly to how modules are found). The provided path is interpreted in a platform-specific way at compile time. So, for instance, an invocation with a Windows path containing backslashes \ would not compile correctly on Unix.

let input = include_bytes!("../input.txt");
println!("{}", String::from_utf8_lossy(input));

short list of annoyances

There's a lot of great things about this language, but there's also some things that are not ideal. In many ways rust feels like a "version one" of a borrow checked language; warts and all.

use tabs

Edit .rustfmt.toml

max_width = 80
hard_tabs = true

https://chrisdone.com/posts/rust/

A better summary of more or less the issues I have with rust.

articles and resources

https://corrode.dev/blog/illegal-state/

Great article about making illegal state unrepresentable.

https://corrode.dev/blog/rust-learning-resources-2025/

A nice list of educational resources