use lupa::{inspect, snapshot, snapshot_diff, RunMode};
use std::collections::HashMap;
#[derive(Debug, Clone)]
struct User {
id: u64,
name: String,
email: String,
age: u32,
role: Role,
address: Address,
tags: Vec<String>,
scores: HashMap<String, f32>,
active: bool,
}
#[derive(Debug, Clone)]
enum Role {
Guest,
Moderator,
Admin { since: String },
}
#[derive(Debug, Clone)]
struct Address {
city: String,
country: String,
zip: String,
}
impl User {
fn new(id: u64, name: &str, email: &str) -> Self {
Self {
id,
name: name.into(),
email: email.into(),
age: 28,
role: Role::Guest,
address: Address {
city: "Berlin".into(),
country: "DE".into(),
zip: "10115".into(),
},
tags: vec!["newcomer".into()],
scores: HashMap::from([
("reputation".into(), 10.0),
("activity".into(), 0.0),
]),
active: true,
}
}
fn promote_to_admin(&mut self) {
self.role = Role::Admin {
since: "2024-06-01".into(),
};
self.tags.push("admin".into());
self.tags.retain(|t| t != "newcomer");
*self.scores.entry("reputation".into()).or_default() += 500.0;
}
fn record_activity(&mut self, points: f32) {
*self.scores.entry("activity".into()).or_default() += points;
self.age += 1;
}
}
fn main() {
let mut user = User::new(42, "Alice", "alice@example.com");
println!("[1/4] Inspecting freshly created user…");
inspect!(user);
let snapshot_before = snapshot!(user);
println!("[2/4] Recording activity…");
user.record_activity(75.5);
inspect!(user);
println!("[3/4] Promoting to Admin…");
user.promote_to_admin();
user.address.city = "Munich".into();
user.address.zip = "80331".into();
inspect!(user);
println!("[4/4] Diffing initial state vs current…");
snapshot_diff!(snapshot_before, user);
println!("\n✅ Done! Check the browser. Press Ctrl+C to exit.");
lupa::run_mode(RunMode::Web).unwrap();
}