#[derive(SwiftField)]
{
// Attributes available to this derive:
#[component]
}
Expand description
Derive macro for SwiftField trait implementation
Generates parsing, serialization, and validation code for SWIFT field structures. Supports component-based field definitions with format specifications.
§Basic Usage
§Simple Field
use swift_mt_message_macros::SwiftField;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
struct Field20 {
#[component("16x")]
reference: String,
}
§Multi-Component Field
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftField)]
struct Field32A {
#[component("6!n")] // Date: YYMMDD
date: String,
#[component("3!a")] // Currency: ISO code
currency: String,
#[component("15d")] // Amount: decimal
amount: f64,
}
§Enum Field (Multiple Variants)
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, SwiftField)]
enum Field50 {
A(Field50A),
F(Field50F),
K(Field50K),
}
§Format Specifications
The #[component("format")]
attribute supports SWIFT format specifications:
- Fixed length:
3!a
(exactly 3 alphabetic chars) - Variable length:
35x
(up to 35 any chars) - Optional:
[/34x]
(optional account with slash prefix) - Repetitive:
4*35x
(up to 4 lines of 35 chars each) - Decimal:
15d
(decimal number up to 15 digits)
§Generated Methods
The macro generates these methods for the SwiftField trait:
parse(value: &str) -> Result<Self>
- Parse from SWIFT format stringto_swift_string(&self) -> String
- Convert to SWIFT format stringformat_spec() -> &'static str
- Return format specification