Skip to content

Rust (Tokio)

  • ✅ Memory safety without garbage collector
  • ✅ Zero-cost abstractions
  • ✅ Compiled to single binary
  • ✅ Fastest performance
  • ✅ No runtime dependencies
use axum::{routing::get, Router};
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", get(|| async { "Hello from Rust!" }));
let listener = tokio::net::TcpListener::bind("0.0.0.0:8000")
.await
.unwrap();
println!("Server running on :8000");
axum::serve(listener, app).await.unwrap();
}
[package]
name = "snapcode"
version = "0.1.0"
edition = "2021"
[dependencies]
axum = "0.7"
tokio = { version = "1", features = ["full"] }
Terminal window
# Development
cargo run
# Release build (optimized)
cargo build --release
# Binary location
./target/release/snapcode
[Unit]
Description=SnapCode Rust Server
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/snapcode
ExecStart=/var/www/snapcode/snapcode
Restart=always
Environment=RUST_LOG=info
[Install]
WantedBy=multi-user.target
// Async/await with Tokio
#[tokio::main]
async fn main() {
// Spawns tasks on thread pool
tokio::spawn(async {
// Background task
});
}
MetricRustGoNode.jsPython
Requests/sec~500K~300K~50K~10K
Memory~5MB~10MB~50MB~30MB
Startup~5ms~10ms~50ms~100ms
Binary size~5MB~10MBN/AN/A
  • ✅ Performance critical applications
  • ✅ System programming
  • ✅ WebAssembly targets
  • ✅ Memory-constrained environments
  • ⚠️ Steeper learning curve