rust

rust
fn greet(name: &str) {
    println!("Hello, {}", name);
}

fn main() {
    let owned = String::from("Alice");

String vs &str for owned vs borrowed text

rust strings
by Marcus Chen 1 tab
rust
use sqlx::PgPool;
use std::time::Duration;
use tokio::sync::mpsc;

#[derive(Debug, Clone)]
pub struct MetricPoint {

Batching Database Writes in Rust with a Size- and Interval-Triggered Flush Buffer

rust tokio sqlx
by codesnips 3 tabs
rust
use std::fmt;
use std::hash::{Hash, Hasher};
use std::marker::PhantomData;
use uuid::Uuid;

pub struct Id<T> {

Type-Safe Entity IDs in Rust with a Zero-Cost Id<T> Newtype

rust newtype type-safety
by codesnips 3 tabs
rust
use std::time::Duration;
use rand::Rng;

#[derive(Clone, Debug)]
pub struct BackoffPolicy {
    pub base_delay: Duration,

Exponential Backoff With Jitter for Retrying Fallible Async Operations in Rust

rust tokio async
by codesnips 3 tabs
rust
use color_eyre::Result;

fn might_fail() -> Result<()> {
    Err(color_eyre::eyre::eyre!("Something went wrong"))
}

color-eyre for beautiful error reports with backtraces

rust error-handling cli
by Marcus Chen 1 tab
rust
use std::time::Duration;
use tokio_util::sync::CancellationToken;

pub struct Worker {
    id: usize,
    token: CancellationToken,

Graceful Task Shutdown in Tokio Using CancellationToken

tokio async cancellation
by codesnips 3 tabs
rust
use serde::{Deserialize, Deserializer};

#[derive(Debug, Deserialize)]
pub struct ListFilter {
    #[serde(default)]
    pub status: Status,

Parse URL Query Strings into a Typed Filter Struct with Defaults in Rust

rust serde query-string
by codesnips 3 tabs
rust
#[derive(Debug, Clone)]
pub enum Outcome {
    Approve,
    Review,
    Reject(String),
}

Modeling and Evaluating a Decision Tree with Recursive Rust Enums

rust enums recursion
by codesnips 3 tabs
rust
use std::mem;

fn main() {
    let mut x = 5;
    let mut y = 10;

std::mem helpers for low-level memory manipulation

rust memory
by Marcus Chen 1 tab
rust
use std::error::Error;
use std::fmt;
use std::io;
use std::num::ParseIntError;

#[derive(Debug)]

Custom Error Enum With From Conversions for the ? Operator in Rust

rust error-handling traits
by codesnips 3 tabs
rust
use std::rc::Rc;
use std::cell::RefCell;

fn main() {
    let data = Rc::new(RefCell::new(vec![1, 2, 3]));

Rc and RefCell for shared ownership with interior mutability

rust smart-pointers interior-mutability
by Marcus Chen 1 tab
rust
struct Logger {
    name: String,
}

impl Drop for Logger {
    fn drop(&mut self) {

Drop trait for custom cleanup logic

rust traits memory-management
by Marcus Chen 1 tab