Created
July 29, 2025 13:53
-
-
Save bplaat/e5871bbcb2889760d66af193ee9fe2a9 to your computer and use it in GitHub Desktop.
Small Rust binary example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| cargo +nightly build --release -Z build-std=std,panic_abort \ | |
| -Z build-std-features=optimize_for_size,panic_immediate_abort |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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