Code Explainers
Rust code explainers
rust
use std::collections::HashMap; use std::sync::{Arc, Mutex}; use std::thread;
Aggregating metrics across threads in Rust
concurrency
shared-state
mutex
Intermediate
7 steps
rust
use std::sync::{mpsc, Arc, Mutex}; use std::thread; use std::time::Duration;
Building a thread pool in Rust
concurrency
channels
thread-pool
Advanced
9 steps
rust
use std::time::Instant; use tracing::info; pub struct Timer {
A scope-guard timer with Drop in Rust
raii
drop-guard
timing
Intermediate
7 steps
rust
use std::collections::HashMap; pub struct Memoizer<K, V, F> { cache: HashMap<K, V>,
A generic memoizer in Rust
memoization
generics
caching
Intermediate
6 steps
rust
use std::collections::HashMap; #[derive(Debug, Clone)] struct Order {
Aggregating Rust data with fold and entry
fold
hashmap
ownership
Intermediate
6 steps
rust
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json}; use serde::{Deserialize, Serialize}; use uuid::Uuid;
Building a typed create_user handler in Axum
serde
extractors
sqlx
Intermediate
7 steps
rust
use axum::{ response::sse::{Event, KeepAlive, Sse}, routing::get, Router,
Streaming live price ticks with SSE in Axum
server-sent-events
broadcast-channel
streaming
Advanced
8 steps
rust
use std::net::SocketAddr; use std::time::Duration; use axum::{routing::get, Json, Router};
Per-IP rate limiting in Axum with tower-governor
rate-limiting
middleware
tower
Intermediate
7 steps
rust
use axum::{ body::Body, extract::Request, http::{header::HeaderValue, HeaderName},
Request ID middleware in Axum
middleware
tracing
request-extensions
Intermediate
7 steps
rust
use std::collections::HashMap; pub fn word_frequencies(text: &str) -> HashMap<String, usize> { let mut counts: HashMap<String, usize> = HashMap::new();
Counting and ranking words in Rust
hashmap
iterators
sorting
Intermediate
7 steps
rust
use std::error::Error; use std::fmt; #[derive(Debug)]
Building a typed error enum in Rust
error-handling
enums
trait-implementation
Intermediate
9 steps
rust
use std::time::Duration; use axum::{routing::get, Router}; use tokio::net::TcpListener;
Graceful shutdown in an Axum server
graceful-shutdown
signal-handling
async
Intermediate
8 steps
rust
use std::fs::File; use std::io::{self, BufRead, BufReader}; use std::path::Path;
Buffered log scanning in Rust
buffered-io
error-handling
streaming
Intermediate
9 steps
rust
use axum::{ extract::{Path, State}, routing::{get, post}, Json, Router,
Building a nested REST API router in Axum
routing
extractors
shared-state
Intermediate
8 steps
rust
use axum::{ extract::State, http::StatusCode, response::IntoResponse,
An async job queue handler in Axum
background-jobs
async
http-202
Intermediate
9 steps
rust
use axum::{ extract::FromRequestParts, http::{request::Parts, StatusCode, header::AUTHORIZATION}, };
How a JWT extractor works in Axum
authentication
jwt
extractors
Intermediate
8 steps
rust
use axum::{extract::Form, http::StatusCode, response::{IntoResponse, Response}, Json}; use serde::Deserialize; use serde_json::json; use std::collections::HashMap;
Validating a signup form in Axum
form-validation
deserialization
error-handling
Intermediate
8 steps
rust
use axum::{ body::Body, extract::Path, http::{header, StatusCode},
Streaming file downloads in Axum
streaming
file-serving
path-traversal
Intermediate
8 steps