| name | rust_development |
| description | Rust systems programming, memory safety, Axum/Tokio ve WebAssembly rehberi. |
🦀 Rust Development
Rust systems programming rehberi.
📋 Temel Syntax
let x = 5;
let mut y = 10;
fn add(a: i32, b: i32) -> i32 {
a + b
}
struct User {
name: String,
age: u32,
}
enum Status {
Active,
Inactive,
Pending(String),
}
🔒 Ownership & Borrowing
let s1 = String::from("hello");
let s2 = s1;
fn print(s: &String) {
println!("{}", s);
}
fn append(s: &mut String) {
s.push_str(" world");
}
⚡ Axum Web Framework
use axum::{routing::get, Router, Json};
use serde::Serialize;
#[derive(Serialize)]
struct User { name: String }
async fn get_user() -> Json<User> {
Json(User { name: "John".into() })
}
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/user", get(get_user));
axum::serve(listener, app).await.unwrap();
}
🔄 Async with Tokio
use tokio;
#[tokio::main]
async fn main() {
let result = fetch_data().await;
}
async fn fetch_data() -> String {
tokio::time::sleep(Duration::from_secs(1)).await;
"data".to_string()
}
🎯 Error Handling
use anyhow::Result;
use thiserror::Error;
#[derive(Error, Debug)]
enum AppError {
#[error("Not found: {0}")]
NotFound(String),
}
fn find_user(id: &str) -> Result<User> {
Ok(user)
}
Rust Development v1.1 - Enhanced
🔄 Workflow
Kaynak: Rust API Guidelines & Zero To Production in Rust
Aşama 1: Project Setup & Structure
Aşama 2: Implementation Patterns
Aşama 3: Performance & Reliability
Kontrol Noktaları
| Aşama | Doğrulama |
|---|
| 1 | cargo clippy hatasız geçiyor mu? ve cargo fmt uygulandı mı? |
| 2 | Tüm public API'ler dökümante edildi mi? (/// doc comments). |
| 3 | Docker imajı distroless veya alpine tabanlı optimize edildi mi? |