rust

rust
fn main() {
    let numbers = vec![1, 2, 3, 4, 5];

    let sum: i32 = numbers
        .iter()
        .filter(|&&x| x % 2 == 0)

Iterator trait and combinators for zero-cost collection processing

rust iterators functional
by Marcus Chen 1 tab
rust
use std::collections::HashMap;
use std::hash::Hash;

const NIL: usize = usize::MAX;

struct Node<K, V> {

Build an O(1) LRU Cache in Rust With a HashMap and Intrusive Doubly Linked List

rust lru cache
by codesnips 3 tabs
rust
trait Container {
    type Item;
    fn get(&self, index: usize) -> Option<&Self::Item>;
}

struct Warehouse {

Associated types in traits for cleaner generics

rust traits generics
by Marcus Chen 1 tab
rust
use std::env;

fn main() {
    let port: u16 = env::var("PORT")
        .unwrap_or_else(|_| "8080".to_string())
        .parse()

Environment variables with std::env for configuration

rust config environment
by Marcus Chen 1 tab
rust
use std::collections::VecDeque;

fn main() {
    let mut queue = VecDeque::new();
    queue.push_back(1);
    queue.push_back(2);

VecDeque<T> for double-ended queue operations

rust collections
by Marcus Chen 1 tab
rust
use std::os::raw::c_int;

pub const LOCK_EX: c_int = 2;
pub const LOCK_NB: c_int = 4;
pub const LOCK_UN: c_int = 8;

RAII File Lock Guard in Rust With Drop-Based Release

rust raii drop
by codesnips 3 tabs
rust
use axum::{routing::get, Router, Json};
use serde::Serialize;

#[derive(Serialize)]
struct Response {
    message: String,

axum for type-safe async HTTP servers

rust async axum
by Marcus Chen 1 tab
rust
use tokio::time::{sleep, Duration};

#[tokio::main]
async fn main() {
    let fast = sleep(Duration::from_millis(50));
    let slow = sleep(Duration::from_millis(200));

tokio::select! for racing multiple async operations

rust async tokio
by Marcus Chen 1 tab
rust
use std::sync::Arc;
use std::time::{Duration, Instant};
use tokio::sync::Mutex;
use tokio::time::sleep;

#[derive(Debug)]

Rate-Limiting Outbound HTTP with a Token Bucket in Rust (Tokio)

rust tokio rate-limiting
by codesnips 3 tabs
rust
use std::collections::HashSet;
use std::hash::Hash;

pub struct DedupByKey<I, K, F> {
    inner: I,
    key_fn: F,

Order-Preserving Stream Deduplication by Key in Rust with a HashSet Guard

rust streams deduplication
by codesnips 3 tabs
rust
use criterion::{black_box, criterion_group, criterion_main, Criterion};

fn fibonacci(n: u64) -> u64 {
    match n {
        0 => 1,
        1 => 1,

Criterion for benchmarking with statistical analysis

rust benchmarking performance
by Marcus Chen 1 tab
rust
use std::fmt::Display;

fn print_it<T: Display>(value: T) {
    println!("Value: {}", value);
}

Trait bounds for generic functions with behavior constraints

rust traits generics
by Marcus Chen 1 tab