Code Explainers

Rust code explainers

rust
use axum::{
    async_trait,
    extract::FromRequestParts,
    http::{request::Parts, StatusCode},

A proof-of-work extractor in Axum

proof-of-work extractors hashing
Advanced 9 steps
rust
use std::collections::HashMap;
use std::sync::Arc;
 
use axum::body::Bytes;

A concurrent webhook dispatcher in Axum

trait-objects concurrency shared-state
Intermediate 9 steps
rust
use serde_json::{Map, Value};
 
pub fn merge_config(base: &mut Value, override_with: Value) {
    match (base, override_with) {

Deep-merging JSON config layers in Rust

recursion json pattern-matching
Intermediate 9 steps
rust
use axum::{
    extract::{Path, State},
    http::HeaderMap,
    response::{Html, IntoResponse},

Building an HTMX-aware toggle handler in Axum

extractors htmx sqlx
Intermediate 8 steps
rust
use rand::Rng;
 
#[derive(Debug)]
pub struct WeightedChoice<T> {

Weighted random sampling in Rust

weighted-sampling generics binary-search
Intermediate 7 steps
rust
use std::collections::BTreeSet;
 
#[derive(Debug)]
pub enum FieldError {

Parsing a cron field in Rust

parsing error-handling enums
Intermediate 7 steps
rust
use axum::{
    body::Body,
    extract::State,
    http::{Request, StatusCode},

A sliding-window rate limiter in Axum

rate-limiting middleware sliding-window
Intermediate 10 steps
rust
use hmac::{Hmac, Mac};
use sha2::Sha256;
use subtle::ConstantTimeEq;
 

HMAC signing and constant-time verify in Rust

hmac cryptography constant-time
Intermediate 7 steps
rust
use axum::{
    extract::{Path, State},
    routing::{get, post},
    Json, Router,

Composing Axum apps from feature modules

trait objects modular routing shared state
Intermediate 8 steps
rust
use axum::{
    extract::{Path, State},
    http::StatusCode,
    Json,

Distinguishing absent from null in an Axum PATCH

partial-update serde nullable-fields
Advanced 8 steps
rust
use std::collections::HashMap;
use std::future::Future;
use std::hash::Hash;
use std::sync::{Arc, Mutex};

Deduplicating concurrent work in Rust

concurrency deduplication async
Advanced 7 steps
rust
use itertools::Itertools;
use std::cmp::Ordering;
 
#[derive(Debug, Clone)]

Merging sorted event streams with itertools

iterators merge deduplication
Intermediate 7 steps
rust
use std::sync::Arc;
 
use axum::{
    extract::{FromRef, State},

Substate extraction with FromRef in Axum

state-management routing middleware
Intermediate 8 steps
rust
use std::sync::Arc;
use std::collections::HashMap;
use axum::{
    extract::State,

Hot-reloadable config with shared state in Axum

shared-state concurrency rwlock
Intermediate 7 steps
rust
use chrono::{DateTime, Duration, Utc};
 
#[derive(Debug, Clone)]
pub struct Sample {

Forward-filling a time series in Rust

time-series forward-fill btreemap
Intermediate 7 steps
rust
use axum::{
    async_trait,
    extract::FromRequestParts,
    http::{header::HeaderName, request::Parts, StatusCode},

A custom tenant extractor in Axum

extractors middleware error-handling
Intermediate 7 steps
rust
#[derive(Debug, Deserialize)]
pub struct SearchParams {
    #[serde(default)]
    q: String,

Building a safe search query in Axum

query parameters deserialization sql-building
Intermediate 10 steps
rust
use axum::{
    body::Body,
    extract::State,
    http::{header, StatusCode},

Streaming a DB migration with Axum

streaming keyset-pagination backpressure
Advanced 8 steps