Skip to content

Commit 7a40ceb

Browse files
committed
refactor: remove raw field from BIC struct and update formatting logic
This commit removes the `raw` field from the `BIC` struct and modifies the `Display` implementation to format the BIC using its individual components: bank code, country code, location code, and branch code. Additionally, the validation logic is updated to check the lengths of these components instead of the removed `raw` field, ensuring more accurate BIC validation.
1 parent 136a346 commit 7a40ceb

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

swift-mt-message/src/fields/common/bic_field.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub struct GenericBicField {
1414

1515
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1616
pub struct BIC {
17-
pub raw: String,
1817
pub bank_code: String,
1918
pub country_code: String,
2019
pub location_code: String,
@@ -25,7 +24,14 @@ pub struct BIC {
2524

2625
impl std::fmt::Display for BIC {
2726
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28-
write!(f, "{}", self.raw)
27+
write!(
28+
f,
29+
"{}{}{}{}",
30+
self.bank_code,
31+
self.country_code,
32+
self.location_code,
33+
self.branch_code.as_ref().unwrap_or(&"".to_string())
34+
)
2935
}
3036
}
3137

@@ -44,7 +50,6 @@ impl std::str::FromStr for BIC {
4450
}
4551

4652
Ok(BIC {
47-
raw: s.to_string(),
4853
bank_code: s[0..4].to_string(),
4954
country_code: s[4..6].to_string(),
5055
location_code: s[6..8].to_string(),
@@ -113,7 +118,10 @@ impl crate::SwiftField for GenericBicField {
113118
let mut warnings = Vec::new();
114119

115120
// Validate BIC length (more lenient validation)
116-
if self.bic.raw.len() < 8 {
121+
if self.bic.bank_code.len() < 4
122+
|| self.bic.country_code.len() < 2
123+
|| self.bic.location_code.len() < 2
124+
{
117125
errors.push(crate::ValidationError::FormatValidation {
118126
field_tag: "GENERICBICFIELD".to_string(),
119127
message: "BIC must be at least 8 characters".to_string(),

0 commit comments

Comments
 (0)