...
This commit is contained in:
47
heromodels/src/lib.rs
Normal file
47
heromodels/src/lib.rs
Normal file
@@ -0,0 +1,47 @@
|
||||
//! # Hero Models
|
||||
//!
|
||||
//! A library for hero models with base model trait implementation.
|
||||
//!
|
||||
//! This crate provides a base model trait and implementation that other models can inherit from.
|
||||
//! It also provides a Comment model that can be used to add comments to any model.
|
||||
|
||||
pub mod model;
|
||||
pub mod comment;
|
||||
pub mod user;
|
||||
|
||||
// Re-export key types for convenience
|
||||
pub use model::{BaseModel, BaseModelData, IndexKey, impl_base_model};
|
||||
pub use comment::Comment;
|
||||
pub use user::User;
|
||||
|
||||
/// Example of how to use the heromodels crate
|
||||
///
|
||||
/// ```rust
|
||||
/// use heromodels::{BaseModel, User, Comment};
|
||||
///
|
||||
/// // Create a new user
|
||||
/// let mut user = User::new(
|
||||
/// 1,
|
||||
/// "johndoe".to_string(),
|
||||
/// "john.doe@example.com".to_string(),
|
||||
/// "John Doe".to_string()
|
||||
/// );
|
||||
///
|
||||
/// // Create a comment for the user
|
||||
/// let comment = Comment::new(
|
||||
/// 1,
|
||||
/// 2, // commenter's user ID
|
||||
/// user.get_id(),
|
||||
/// User::db_prefix().to_string(),
|
||||
/// "This is a comment on the user".to_string()
|
||||
/// );
|
||||
///
|
||||
/// // Add the comment to the user
|
||||
/// user.base_data.add_comment(comment.get_id());
|
||||
///
|
||||
/// // Get the database prefix for the User model
|
||||
/// assert_eq!(User::db_prefix(), "user");
|
||||
///
|
||||
/// // Get the database keys for the user
|
||||
/// let keys = user.db_keys();
|
||||
/// assert!(keys.iter().any(|k| k.name == "username" && k.value == "johndoe"));
|
Reference in New Issue
Block a user