use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct User {
pub id: u64,
pub name: String,
pub email: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Role {
Admin,
User,
Guest,
}
pub fn process_user(user: &User) -> Result<String, String> {
if user.name.is_empty() {
return Err("Name cannot be empty".to_string());
}
let formatted = format!("User: {} ({})", user.name, user.email);
Ok(formatted)
}
pub fn calculate_total(values: &[i32]) -> i32 {
values.iter().sum()
}
pub fn main() {
let user = User {
id: 1,
name: "Alice".to_string(),
email: "alice@example.com".to_string(),
};
match process_user(&user) {
Ok(result) => println!("{}", result),
Err(e) => eprintln!("Error: {}", e),
}
let numbers = vec![1, 2, 3, 4, 5];
let total = calculate_total(&numbers);
println!("Total: {}", total);
}