Struct Field21

Source
pub struct Field21 {
    pub related_reference: String,
}
Expand description

§Overview

Field 21 contains the sender’s reference to the related transaction or message. This field establishes a link between the current message and a previously sent message or transaction, enabling tracking of related operations and maintaining audit trails across multiple message exchanges in correspondent banking and payment processing workflows.

§Format Specification

Format: 16x

  • 16x: Up to 16 alphanumeric characters
  • Character set: A-Z, a-z, 0-9, and limited special characters
  • Case sensitivity: Preserved as entered
  • Padding: No padding required (variable length up to 16 characters)

§Structure and Content

The related reference typically links to:

FT21034567890123
│└─────────────┘
│  Related transaction reference
└── Transaction type prefix (optional)

§Common Reference Patterns

Different institutions use various patterns for related references:

  • Sequential linking: REL000001, REL000002, REL000003
  • Original reference: Same as Field 20 from original message
  • Cover references: COV001234567, COV987654321
  • Amendment references: AMD1234567890, AMD0987654321
  • Cancellation references: CAN12345678, CAN87654321

§Usage Context

Field 21 is used in numerous SWIFT MT message types:

  • MT202: General Financial Institution Transfer
  • MT202COV: Cover for customer credit transfer
  • MT205: Financial Institution Transfer for its own account
  • MT210: Notice to Receive
  • MT292: Request for Cancellation
  • MT296: Answer to Amendment/Cancellation Request

§Business Applications

  • Transaction linking: Connecting related messages and transactions
  • Cover operations: Linking cover messages to original customer transfers
  • Amendment tracking: Referencing original messages in amendments
  • Cancellation requests: Identifying transactions to be cancelled
  • Reconciliation: Matching related transactions across systems
  • Audit trails: Maintaining complete transaction history chains
  • Regulatory reporting: Providing transaction relationship information

§Validation Rules

  1. Length: Maximum 16 characters
  2. Character set: Alphanumeric characters and limited special characters
  3. Non-empty: Cannot be empty or contain only whitespace
  4. Format consistency: Should follow institutional standards
  5. Relationship validity: Should reference valid related transactions

§Network Validated Rules (SWIFT Standards)

  • Related reference must not exceed 16 characters (Error: T13)
  • Must contain valid SWIFT character set (Error: T61)
  • Cannot be empty (Error: T18)
  • Should reference existing transaction when applicable (Warning: recommended practice)

§Examples

:21:FT21234567890
└─── Related wire transfer reference

:21:COV0000012345
└─── Cover message reference

:21:NYC20241201001
└─── Branch and date-based related reference

:21:AMD123456789A
└─── Amendment reference with check digit

Fields§

§related_reference: String

Related reference value (maximum 16 characters)

Contains the sender’s reference to the related transaction or message. This value establishes the link between the current message and a previously sent message, enabling transaction tracking and audit trails.

Format: Up to 16 alphanumeric characters Character set: A-Z, a-z, 0-9, and limited special characters Case sensitivity: Preserved as entered Purpose: Links current message to related transaction or message

§Examples

  • "FT21234567890" - Related wire transfer reference
  • "COV0000012345" - Cover message reference
  • "AMD20241201001" - Amendment reference
  • "CAN123456789A" - Cancellation reference with check digit

Implementations§

Source§

impl Field21

Source

pub fn new(related_reference: String) -> Self

Create a new Field21 with comprehensive validation

Creates a new related reference field with the provided reference string. The reference is validated for length and character set compliance.

§Arguments
  • related_reference - The related reference string (max 16 chars)
§Examples
use swift_mt_message::fields::Field21;

// Standard related reference
let field = Field21::new("FT21234567890".to_string());

// Cover message reference
let field = Field21::new("COV0000012345".to_string());

// Amendment reference
let field = Field21::new("AMD20241201001".to_string());
§Validation

The constructor performs basic validation but full validation occurs when calling validate() method or during SWIFT message processing.

Source

pub fn related_reference(&self) -> &str

Get the related reference value

Returns the related reference string that links this message to a previously sent message or transaction.

§Returns

A string slice containing the related reference

§Example
let field = Field21::new("FT21234567890".to_string());
assert_eq!(field.related_reference(), "FT21234567890");
Source

pub fn reference_pattern(&self) -> &'static str

Check if the reference follows a common pattern

Analyzes the related reference to determine if it follows common institutional patterns for reference generation.

§Returns

A string describing the detected pattern, or “Custom” if no pattern is detected

§Example
let cover_ref = Field21::new("COV21234567890".to_string());
assert_eq!(cover_ref.reference_pattern(), "Cover Message");

let amd_ref = Field21::new("AMD0000012345".to_string());
assert_eq!(amd_ref.reference_pattern(), "Amendment");
Source

pub fn is_date_based(&self) -> bool

Check if the reference appears to be date-based

Determines if the related reference contains date information based on common date patterns in reference strings.

§Returns

true if the reference appears to contain date information

§Example
let date_ref = Field21::new("20241201001".to_string());
assert!(date_ref.is_date_based());

let simple_ref = Field21::new("COV12345".to_string());
assert!(!simple_ref.is_date_based());
Source

pub fn sequence_number(&self) -> Option<u32>

Extract potential sequence number from reference

Attempts to extract a sequence number from the related reference, which is commonly found at the end of structured references.

§Returns

Some(number) if a sequence number is found, None otherwise

§Example
let seq_ref1 = Field21::new("COV001".to_string());
assert_eq!(seq_ref1.sequence_number(), Some(1));

let seq_ref2 = Field21::new("AMD123456789".to_string());
assert_eq!(seq_ref2.sequence_number(), Some(123456789));

let seq_ref3 = Field21::new("CAN000000042".to_string());
assert_eq!(seq_ref3.sequence_number(), Some(42));

let no_seq1 = Field21::new("CUSTOMREF".to_string());
assert_eq!(no_seq1.sequence_number(), None);

let no_seq2 = Field21::new("COV_NO_NUM".to_string());
assert_eq!(no_seq2.sequence_number(), None);

let all_num = Field21::new("123456789".to_string());
assert_eq!(all_num.sequence_number(), Some(123456789));

let too_long = Field21::new("AMD12345678901".to_string());
assert_eq!(too_long.sequence_number(), None);
Source

pub fn is_cover_reference(&self) -> bool

Check if this is a cover message reference

Determines if the related reference indicates this is related to a cover message operation.

§Returns

true if the reference appears to be for a cover message

§Example
let cover_ref = Field21::new("COV21234567890".to_string());
assert!(cover_ref.is_cover_reference());

let regular_ref = Field21::new("FT12345".to_string());
assert!(!regular_ref.is_cover_reference());
Source

pub fn is_amendment_reference(&self) -> bool

Check if this is an amendment reference

Determines if the related reference indicates this is related to an amendment operation.

§Returns

true if the reference appears to be for an amendment

§Example
let amd_ref = Field21::new("AMD21234567890".to_string());
assert!(amd_ref.is_amendment_reference());

let regular_ref = Field21::new("FT12345".to_string());
assert!(!regular_ref.is_amendment_reference());
Source

pub fn is_cancellation_reference(&self) -> bool

Check if this is a cancellation reference

Determines if the related reference indicates this is related to a cancellation operation.

§Returns

true if the reference appears to be for a cancellation

§Example
let can_ref = Field21::new("CAN21234567890".to_string());
assert!(can_ref.is_cancellation_reference());

let regular_ref = Field21::new("FT12345".to_string());
assert!(!regular_ref.is_cancellation_reference());
Source

pub fn description(&self) -> String

Get a human-readable description of the related reference

Returns a descriptive string explaining the related reference format and detected patterns.

§Returns

A descriptive string

§Example
let field = Field21::new("COV21234567890".to_string());
println!("{}", field.description());
Source

pub fn is_well_formed(&self) -> bool

Validate reference format according to institutional standards

Performs additional validation beyond the standard SWIFT field validation, checking for common institutional reference format requirements.

§Returns

true if the reference follows good practices, false otherwise

§Example
let good_ref1 = Field21::new("COV21234567890".to_string());
assert!(good_ref1.is_well_formed());

let good_ref2 = Field21::new("AMD-123456".to_string());
assert!(good_ref2.is_well_formed());

let good_ref3 = Field21::new("REL_001.234".to_string());
assert!(good_ref3.is_well_formed());

let good_ref4 = Field21::new("CAN/12345".to_string());
assert!(good_ref4.is_well_formed());

let too_short = Field21::new("AB".to_string());
assert!(!too_short.is_well_formed());

let all_same = Field21::new("AAAAAAA".to_string());
assert!(!all_same.is_well_formed());

let invalid_chars = Field21::new("REF@123#".to_string());
assert!(!invalid_chars.is_well_formed());

let spaces = Field21::new("REF 123".to_string());
assert!(!spaces.is_well_formed());

Trait Implementations§

Source§

impl Clone for Field21

Source§

fn clone(&self) -> Field21

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Field21

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Field21

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Field21

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Field21

Source§

fn eq(&self, other: &Field21) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Field21

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl SwiftField for Field21

Source§

fn parse(value: &str) -> Result<Self>

Parse field value from string representation
Source§

fn to_swift_string(&self) -> String

Convert field back to SWIFT string format
Source§

fn validate(&self) -> ValidationResult

Validate field according to SWIFT format rules
Source§

fn format_spec() -> &'static str

Get field format specification
Source§

impl StructuralPartialEq for Field21

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,