db/heromodels/examples/custom_model_example.rs
Lee Smet b8e1449ddb
Restructure crates for correct proc macro usage
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
2025-04-25 13:58:17 +02:00

38 lines
959 B
Rust

use heromodels_core::{BaseModelData, Model};
use heromodels_derive::model;
use serde::{Deserialize, Serialize};
// Define a custom attribute for indexing
#[derive(Debug, Clone, Serialize, Deserialize)]
#[model]
pub struct CustomUser {
pub base_data: BaseModelData,
// Mark fields for indexing with attributes
#[index]
pub login: String,
#[index]
pub is_active: bool,
pub full_name: String,
}
fn main() {
println!("Hero Models - Custom Model Example");
println!("==================================");
// Example usage of the generated implementation
println!("CustomUser DB Prefix: {}", CustomUser::db_prefix());
let user = CustomUser {
base_data: BaseModelData::new(1),
login: "johndoe".to_string(),
is_active: true,
full_name: "John Doe".to_string(),
};
println!("\nCustomUser ID: {}", user.get_id());
println!("CustomUser DB Keys: {:?}", user.db_keys());
}