qubit-mixin
Trait mixins for domain objects, providing common properties and behaviors.
Overview
qubit-mixin provides a collection of trait mixins that can be composed together to add common functionality to domain objects. These traits follow the principle of composition over inheritance and allow domain objects to gain required functionality by implementing different trait combinations.
Features
- Timestamp Traits: Manage creation time, modification time, and deletion time
- Identifier Traits: Provide ID, code, name and other identification information
- State Management Traits: Manage status, visibility and other states
- User Information Traits: Provide username, email, password and other user-related information
- Entity Association Traits: Manage entity relationships
- Validation & Normalization: Provide data validation and normalization functionality
Installation
Add this to your Cargo.toml:
[]
= "0.2"
On crates.io the package is qubit-mixin; in Rust code, import it as qubit_mixin (hyphens map to underscores in the crate root). If you used the former prism3-mixin / prism3_mixin, switch the dependency key to qubit-mixin and update use paths to qubit_mixin.
Usage
use ;
use ;
let mut product = Product ;
// Use the trait methods
assert_eq!;
assert_eq!;
assert!;
Available Traits
Basic Traits
Identifiable: Provides unique identifier (ID)WithCode: Provides code propertyWithName: Provides name propertyWithComment: Provides comment propertyWithEmail: Provides email propertyWithUsername: Provides username propertyWithPassword: Provides password propertyWithBirthday: Provides birthday propertyWithIndex: Provides index propertyWithKey: Provides key propertyWithSecurityKey: Provides security key propertyWithUdid: Provides device unique identifierWithUuid: Provides universally unique identifierWithStatus: Provides status propertyWithVisibility: Provides visibility propertyWithEntity: Provides entity association
Timestamp Traits
Creatable: Records creation timeModifiable: Records last modification timeDeletable: Records deletion time (soft delete)Auditable: Combines creation, modification, and deletion timestamps
Functional Traits
Emptyful: Providesis_empty()methodNormalizable: Provides data normalization functionalityPredefinable: Indicates whether object is predefinedValidatable: Provides data validation functionalityDesensitizable: Provides sensitive data desensitizationDataWithMaxAge: Defines maximum age for data
Information Traits
HasSpecificInfo<T>: Provides specific information accessHasInfo: Provides basic information accessHasInfoWithEntity<E>: Provides basic information with entity association
Data Structures
Info: Basic information structure (ID, code, name, delete_time)InfoWithEntity<E>: Basic information with entity association
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Author
Haixing Hu