Skip to content

Instantly share code, notes, and snippets.

@bplaat
Created July 29, 2025 13:53
Show Gist options
  • Save bplaat/e5871bbcb2889760d66af193ee9fe2a9 to your computer and use it in GitHub Desktop.
Save bplaat/e5871bbcb2889760d66af193ee9fe2a9 to your computer and use it in GitHub Desktop.
Small Rust binary example
#!/bin/sh
cargo +nightly build --release -Z build-std=std,panic_abort \
-Z build-std-features=optimize_for_size,panic_immediate_abort
[package]
name = "hello"
version = "0.1.0"
edition = "2024"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
[profile.release]
strip = true
opt-level = "z"
lto = true
panic = "abort"
use serde::Serialize;
// MARK: Person
#[derive(Serialize)]
struct Person {
name: String,
age: u32,
}
impl Person {
fn new(name: String, age: u32) -> Self {
Person { name, age }
}
}
// MARK: Main
fn main() {
let mut persons = Vec::new();
persons.push(Person::new("Alice".to_string(), 30));
persons.push(Person::new("Bob".to_string(), 25));
persons.push(Person::new("Charlie".to_string(), 35));
persons.push(Person::new("Diana".to_string(), 28));
println!("{}", serde_json::to_string(&persons).unwrap());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment