rust

rust
use tokio::time::{sleep, Duration};

#[tokio::main]
async fn main() {
    let handle = tokio::spawn(async {
        sleep(Duration::from_millis(100)).await;

tokio::spawn for concurrent task execution

rust async tokio
by Marcus Chen 1 tab
rust
use std::str::FromStr;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Frequency {
    Daily,
    Weekly,

Parse iCalendar RRULE and Recurrence Data into Typed Rust Enums

rust parsing icalendar
by codesnips 3 tabs
rust
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use uuid::Uuid;

#[derive(Debug, Clone, Serialize, Deserialize)]

Cursor-Paginated Streaming REST Endpoint in Axum with Keyset Pagination

axum rust pagination
by codesnips 3 tabs
rust
use serde::{Deserialize, Deserializer};
use time::OffsetDateTime;

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UserProfile {

Deserializing Optional and Renamed JSON API Fields with Serde in Rust

rust serde serde-json
by codesnips 2 tabs
rust
#[cfg(target_os = "linux")]
fn platform_specific() {
    println!("Running on Linux");
}

#[cfg(target_os = "windows")]

cfg attribute for conditional compilation

rust conditional-compilation
by Marcus Chen 1 tab
rust
#[derive(Debug, Clone, PartialEq)]
struct Point {
    x: i32,
    y: i32,
}

Derive macros for automatic trait implementations

rust macros traits
by Marcus Chen 1 tab
rust
use std::collections::HashMap;
use serde_json::Value;

#[derive(Debug)]
pub enum DispatchError {
    UnknownCommand(String),

Compile-Time Command Dispatch Table With a Rust Declarative Macro

rust macros dispatch
by codesnips 3 tabs
rust
const CONSECUTIVE_BONUS: f64 = 8.0;
const WORD_START_BONUS: f64 = 10.0;
const MATCH_BASE: f64 = 4.0;
const LEADING_PENALTY: f64 = 0.5;

#[derive(Debug, Clone, Copy)]

Fuzzy Search Ranker with Subsequence Matching and Score-Based Sorting in Rust

fuzzy-search ranking algorithms
by codesnips 3 tabs
rust
use tokio::sync::mpsc::{self, Sender};
use tokio::sync::mpsc::error::TrySendError;

use crate::email::{EmailJob, EmailMessage};
use crate::worker::EmailWorker;

Retry-Aware Email Queue With a Tokio mpsc Worker and Exponential Backoff

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

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct CancelReason {
    pub reason: String,
    pub feedback: Option<String>,

Internally Tagged Enum JSON Serialization for a Rust Webhook API

rust serde json
by codesnips 3 tabs
rust
use serde::Deserialize;

#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Config {
    pub server: ServerConfig,

Parsing a Layered TOML Config into Typed Sections with Serde and Defaults

rust serde toml
by codesnips 3 tabs
rust
enum Status {
    Ok,
    Error(String),
    Pending,
}

Pattern matching with match for exhaustive case handling

rust pattern-matching
by Marcus Chen 1 tab