#[derive(SwiftMessage)]
{
// Attributes available to this derive:
#[field]
#[sequence]
#[validation_rules]
}
Expand description
Derive macro for SwiftMessage trait implementation
Generates message-level parsing, validation, and field management code. Supports field specifications and validation rules for complete SWIFT message types.
§Basic Usage
use swift_mt_message_macros::{SwiftMessage, serde_swift_fields};
use serde::{Deserialize, Serialize};
use crate::fields::*;
#[serde_swift_fields]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, SwiftMessage)]
struct MT103 {
// Mandatory fields (no Option wrapper)
#[field("20")]
field_20: Field20,
#[field("32A")]
field_32a: Field32A,
// Optional fields (wrapped in Option)
#[field("50A")]
field_50a: Option<Field50A>,
// Repetitive fields (wrapped in Vec)
#[field("71A")]
field_71a: Option<Vec<Field71A>>,
}
§Field Attributes
The #[field("tag")]
attribute maps struct fields to SWIFT field tags:
#[field("20")]
- Maps to SWIFT field 20#[field("32A")]
- Maps to SWIFT field 32A with option- Field tags must match the SWIFT standard exactly
§Field Types
- Mandatory:
field_20: Field20
- Required field - Optional:
field_50: Option<Field50>
- Optional field - Repetitive:
field_71a: Vec<Field71A>
- Multiple occurrences - Optional Repetitive:
field_71a: Option<Vec<Field71A>>
- Optional multiple
§Generated Methods
The macro generates these methods for the SwiftMessageBody trait:
message_type() -> &'static str
- Returns message type (e.g., “103”)from_fields(fields: HashMap<String, Vec<String>>) -> Result<Self>
- Parse from field mapto_fields(&self) -> HashMap<String, Vec<String>>
- Convert to field maprequired_fields() -> Vec<&'static str>
- List required field tagsoptional_fields() -> Vec<&'static str>
- List optional field tags