hexser_macros/
lib.rs

1//! Procedural macros for the hex crate.
2//!
3//! This crate provides derive macros that enable zero-boilerplate hexagonal architecture
4//! by automatically implementing registration traits and generating metadata for
5//! compile-time graph construction. Also includes error construction macros with
6//! automatic source location capture.
7//!
8//! # Derive Macros
9//!
10//! - `#[derive(HexDomain)]` - Mark domain layer types
11//! - `#[derive(HexPort)]` - Mark port traits
12//! - `#[derive(HexAdapter)]` - Mark adapter implementations
13//! - `#[derive(Entity)]` - Implement Entity trait
14//! - `#[derive(Repository)]` - Mark repository ports
15//!
16//! # Error Macros
17//!
18//! - `hex_domain_error!(code, message)` - Create domain error with source location
19//! - `hex_port_error!(code, message)` - Create port error with source location
20//! - `hex_adapter_error!(code, message)` - Create adapter error with source location
21//!
22//! # Example
23//!
24//! ```rust,ignore
25//! use hexser::prelude::*;
26//!
27//! #[derive(HexDomain, Entity)]
28//! struct User {
29//!     id: String,
30//!     email: String,
31//! }
32//!
33//! let err = hex_domain_error!("E_HEX_001", "Invalid state");
34//! ```
35//!
36//! Revision History
37//! - 2025-10-06T02:00:00Z @AI: Add error construction macros.
38//! - 2025-10-02T00:00:00Z @AI: Initial Phase 3 proc macro crate.
39
40mod common;
41mod derive;
42mod registration;
43mod error;
44
45#[proc_macro_derive(HexDomain, attributes(hex))]
46pub fn derive_hex_domain(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
47    crate::derive::hex_domain::derive(input)
48}
49
50#[proc_macro_derive(HexPort, attributes(hex))]
51pub fn derive_hex_port(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
52    crate::derive::hex_port::derive(input)
53}
54
55#[proc_macro_derive(HexAdapter, attributes(hex))]
56pub fn derive_hex_adapter(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
57    crate::derive::hex_adapter::derive(input)
58}
59
60#[proc_macro_derive(HexAggregate, attributes(hex))]
61pub fn derive_hex_aggregate(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
62    crate::derive::aggregate::derive(input)
63}
64
65#[proc_macro_derive(Entity)]
66pub fn derive_entity(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
67    crate::derive::entity::derive(input)
68}
69
70#[proc_macro_derive(HexRepository)]
71pub fn derive_repository(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
72    crate::derive::repository::derive(input)
73}
74
75#[proc_macro_derive(HexDirective)]
76pub fn derive_directive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
77    crate::derive::directive::derive(input)
78}
79
80#[proc_macro_derive(HexQuery)]
81pub fn derive_query(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
82    crate::derive::query::derive(input)
83}
84
85#[proc_macro]
86pub fn hex_domain_error(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
87    crate::error::hex_error_macro::hex_domain_error_impl(input)
88}
89
90#[proc_macro]
91pub fn hex_port_error(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
92    crate::error::hex_error_macro::hex_port_error_impl(input)
93}
94
95#[proc_macro]
96pub fn hex_adapter_error(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
97    crate::error::hex_error_macro::hex_adapter_error_impl(input)
98}
99