swift_mt_message_macros/
lib.rs

1use proc_macro::TokenStream;
2
3// Module declarations
4mod component;
5mod derive;
6mod serde;
7mod utils;
8
9use derive::field::derive_swift_field_impl;
10use derive::message::derive_swift_message_impl;
11
12/// Derive macro for SwiftField trait implementation
13///
14/// Supports the component-based approach for defining SWIFT field structures
15/// with validation attributes and format specifications.
16#[proc_macro_derive(SwiftField, attributes(component))]
17pub fn derive_swift_field(input: TokenStream) -> TokenStream {
18    derive_swift_field_impl(input)
19}
20
21/// Derive macro for SwiftMessage trait implementation
22///
23/// Supports message-level business validation with field specifications
24/// and validation rules for complete SWIFT message types.
25#[proc_macro_derive(SwiftMessage, attributes(field, sequence, validation_rules))]
26pub fn derive_swift_message(input: TokenStream) -> TokenStream {
27    derive_swift_message_impl(input)
28}
29
30/// Attribute macro for field specifications
31#[proc_macro_attribute]
32pub fn field(_args: TokenStream, input: TokenStream) -> TokenStream {
33    // For now, this is a no-op that just preserves the field definition
34    // The actual field metadata is extracted by the SwiftMessage derive macro
35    input
36}
37
38/// Attribute macro for message type specifications
39#[proc_macro_attribute]
40pub fn swift_message(_args: TokenStream, input: TokenStream) -> TokenStream {
41    // For now, this is a no-op that just preserves the struct definition
42    // The actual message type metadata is extracted by the SwiftMessage derive macro
43    input
44}
45
46/// Attribute macro that automatically adds serde attributes based on field configurations
47/// Usage: #[serde_swift_fields] before #[derive(...)]
48#[proc_macro_attribute]
49pub fn serde_swift_fields(_args: TokenStream, input: TokenStream) -> TokenStream {
50    serde::serde_swift_fields_impl(input)
51}