| Crates.io | rsmack-seanum |
| lib.rs | rsmack-seanum |
| version | 0.18.0 |
| created_at | 2025-11-12 10:21:51.822345+00 |
| updated_at | 2025-11-16 15:29:08.215944+00 |
| description | Enhanced documentation macro with constant evaluation |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1929068 |
| size | 81,687 |
The seanum procedural macro transforms a simple Rust enum into a fully-featured SeaORM active enum with database mapping capabilities. It automatically adds the necessary attributes, derives, and implementations to make the enum compatible with SeaORM's entity system.
Apply the #[seanum] attribute to an enum definition with the required parameters:
use rsmack_seanum::seanum;
#[seanum(rs_type = String, db_type = "Enum")]
pub enum SwitchAction {
SendEmail,
SendSms,
}
The seanum macro accepts the following parameters:
rs_type (Ident): The Rust type that represents the enum in the database (e.g., String, i32).db_type (LitStr): The database type for the enum (e.g., "Enum", "Text").When applied, the macro transforms the input enum by:
Clone - Enables cloning of the enumDummy - Enables generation of fake data for testingDebug - Enables debug formattingPartialEq - Enables partial equality comparisonEnumIter - Enables iteration over enum variantsDeriveActiveEnum - SeaORM's derive for active enumsEq - Enables full equality comparisonSerialize - Enables serializationDeserialize - Enables deserialization#[sea_orm(...)] attribute to the enum with:
rs_type - The Rust type for the enum in the databasedb_type - The database type for the enumenum_name - The snake_case version of the enum name for database use#[sea_orm(string_value = "...")] attributes to each variant with the string representation of the variant nameuse rsmack_seanum::seanum;
#[seanum(rs_type = String, db_type = "Enum")]
pub enum SwitchAction {
SendEmail,
SendSms,
}
use fake::Dummy;
use sea_orm::entity::prelude::*;
use sea_orm_migration::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(
Clone, Dummy, Debug, PartialEq, EnumIter, DeriveActiveEnum, Eq, Serialize, Deserialize,
)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "switch_action")]
pub enum SwitchAction {
#[sea_orm(string_value = "SendEmail")]
SendEmail,
#[sea_orm(string_value = "SendSms")]
SendSms,
}
SwitchAction becomes switch_action)megamac framework for proper executionThis macro requires the following dependencies:
sea-orm - For the DeriveActiveEnum trait and related attributessea-orm-migration - For database migration supportserde - For serialization and deserializationfake - For generating fake data in tests