rust
11 lines · 1 tab
Marcus Chen
Jan 2026
1 tab
const MAX_SIZE: usize = 1024;
const fn square(n: u32) -> u32 {
n * n
}
const RESULT: u32 = square(5);
fn main() {
println!("Square of 5: {}", RESULT);
}
1 file · rust
Explain with highlit
const defines compile-time constants, and const fn are functions that can run at compile time. I use const for magic numbers, lookup tables, and configuration that never changes. const fn is powerful for building complex constants (like hash maps or arrays) without runtime cost. The restrictions are tight: no heap allocation, no panic, limited operations. As Rust evolves, more features become const-compatible. I use const fn for validators, hash functions, and array initialization. The benefit is zero runtime cost: the computation happens during compilation. For performance-critical code, moving work to compile time can eliminate entire code paths at runtime.
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.