rust

rust
fn calculate_length(s: &String) -> usize {
    s.len()
}

fn append_suffix(s: &mut String) {
    s.push_str(" world");

Borrowing with & and &mut for zero-cost access

rust ownership borrowing
by Marcus Chen 1 tab
rust
use std::io::Write;
use tempfile::NamedTempFile;

fn main() -> std::io::Result<()> {
    let mut tmpfile = NamedTempFile::new()?;
    writeln!(tmpfile, "Hello, temp file!")?;

tempfile for safe temporary file creation

rust testing files
by Marcus Chen 1 tab
rust
use std::collections::HashSet;

fn main() {
    let mut words = HashSet::new();
    words.insert("hello");
    words.insert("world");

HashSet<T> for unique value collections

rust collections
by Marcus Chen 1 tab
rust
struct UserId(u32);

impl From<u32> for UserId {
    fn from(id: u32) -> Self {
        UserId(id)
    }

From and Into for type conversions

rust traits conversion
by Marcus Chen 1 tab
rust
use std::fmt;

struct Point {
    x: i32,
    y: i32,
}

std::fmt::Display for user-facing string representations

rust traits formatting
by Marcus Chen 1 tab
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
use std::marker::PhantomData;

struct Token<'a> {
    _marker: PhantomData<&'a ()>,
}

PhantomData for zero-cost type-level markers

rust generics phantomdata
by Marcus Chen 1 tab
rust
use rayon::prelude::*;

fn main() {
    let numbers: Vec<_> = (0..1000).collect();

    let sum: i32 = numbers

Rayon for data parallelism with par_iter

rust parallelism rayon
by Marcus Chen 1 tab
rust
use log::{info, warn, error};

fn main() {
    env_logger::init();

    info!("Application started");

log crate facade for pluggable logging backends

rust logging
by Marcus Chen 1 tab
rust
fn divide(a: i32, b: i32) -> Option<i32> {
    if b == 0 {
        None
    } else {
        Some(a / b)
    }

Option<T> for explicit null handling

rust option null-safety
by Marcus Chen 1 tab
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
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