rust
12 lines · 1 tab
Marcus Chen
Jan 2026
1 tab
use rayon::prelude::*;
fn main() {
let numbers: Vec<_> = (0..1000).collect();
let sum: i32 = numbers
.par_iter()
.map(|&x| x * x)
.sum();
println!("Sum of squares: {}", sum);
}
1 file · rust
Explain with highlit
Rayon makes data parallelism trivial: replace .iter() with .par_iter(), and your loop runs in parallel across all CPU cores. It uses a work-stealing scheduler to balance load automatically. I use rayon for CPU-bound tasks like image processing, data transformations, or batch computations. The API mirrors standard iterators (.map(), .filter(), .reduce()), so it's easy to adopt. Rayon handles thread pools internally, so you don't manage threads manually. The key is ensuring your closure is Send and doesn't have shared mutable state (use atomics or reduction). For embarrassingly parallel workloads, rayon can give near-linear speedups. It's one of the easiest wins for performance in Rust.
Related snips
rust
struct Config<'a> {
name: &'a str,
value: &'a str,
}
fn parse_config(line: &str) -> Config {
Lifetime annotations for flexible borrowing in structs
rust
lifetimes
borrowing
by Marcus Chen
1 tab
ruby
require "csv"
class PeopleCsvStream
include Enumerable
HEADERS = %w[id full_name email signed_up_at plan].freeze
Resilient CSV Export as a Streamed Response
rails
performance
streaming
by codesnips
3 tabs
rust
use crossbeam::channel::unbounded;
use std::thread;
fn main() {
let (tx, rx) = unbounded();
Crossbeam for advanced concurrent data structures
rust
concurrency
lock-free
by Marcus Chen
1 tab
ruby
Rails.application.configure do
config.after_initialize do
Bullet.enable = true
Bullet.alert = false
Bullet.bullet_logger = true
Bullet.console = true
N+1 query detection with Bullet gem
rails
performance
activerecord
by Alex Kumar
2 tabs
rust
use tracing::{info, instrument};
#[instrument]
fn process_request(user_id: u64) {
info!(user_id, "Processing request");
// Work happens here
tracing for structured logging and distributed tracing
rust
observability
tracing
by Marcus Chen
1 tab
rust
use std::sync::mpsc;
use std::thread;
fn main() {
let (tx, rx) = mpsc::channel();
Channels (mpsc) for message passing between threads
rust
concurrency
channels
by Marcus Chen
1 tab
Share this code
Here's the card — post it anywhere.