Marcus Chen

78 code snips · on codesnips 5 months

Rust systems engineer building high-performance tools and services. Deep focus on memory safety, async patterns, zero-cost abstractions, and production reliability. 10+ years in...

rust
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::thread;

fn main() {
    let counter = Arc::new(AtomicUsize::new(0));

Atomic operations for lock-free concurrency

rust concurrency atomics
by Marcus Chen 1 tab
rust
extern "C" {
    fn abs(input: i32) -> i32;
}

pub fn safe_abs(input: i32) -> i32 {
    unsafe { abs(input) }

Unsafe Rust for FFI and low-level optimizations

rust unsafe ffi
by Marcus Chen 1 tab
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 my_crate::add;

#[test]
fn test_public_api() {
    assert_eq!(add(3, 4), 7);
}

Integration tests in tests/ directory

rust testing integration
by Marcus Chen 1 tab
rust
pub fn add(a: i32, b: i32) -> i32 {
    a + b
}

#[cfg(test)]
mod tests {

Unit tests with #[test] and assert macros

rust testing
by Marcus Chen 1 tab
toml
[features]
default = ["json"]
json = ["serde_json"]
yaml = ["serde_yaml"]

[dependencies]

Feature flags for conditional compilation

rust cargo features
by Marcus Chen 2 tabs
toml
[workspace]
members = [
    "server",
    "client",
    "common",
]

Cargo workspaces for multi-crate projects

rust cargo workspace
by Marcus Chen 1 tab
rust
use sqlx::PgPool;

#[derive(sqlx::FromRow)]
struct User {
    id: i32,
    name: String,

sqlx for compile-time checked SQL queries with async

rust database sql
by Marcus Chen 1 tab
rust
use axum::{Router, routing::get};
use tower::ServiceBuilder;
use tower_http::{trace::TraceLayer, timeout::TimeoutLayer};
use std::time::Duration;

async fn handler() -> &'static str {

Tower middleware for composable HTTP service layers

rust tower middleware
by Marcus Chen 1 tab
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 reqwest;
use serde::Deserialize;

#[derive(Deserialize, Debug)]
struct Post {
    id: u32,

reqwest for async HTTP client with connection pooling

rust http async
by Marcus Chen 1 tab
rust
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
struct Config {
    host: String,
    port: u16,

serde for zero-copy serialization and deserialization

rust serde serialization
by Marcus Chen 1 tab