| 76 | } |
| 77 | |
| 78 | fn validate_labels(labels: &[String]) -> ModelValidatorResult<AddressBookError> { |
| 79 | for label in labels { |
| 80 | if label.is_empty() { |
| 81 | return Err(AddressBookError::ValidationError { |
| 82 | info: "Label entry cannot be empty".to_string(), |
| 83 | }); |
| 84 | } |
| 85 | |
| 86 | if label.len() > AddressBookEntry::MAX_LABEL_LENGTH { |
| 87 | return Err(AddressBookError::ValidationError { |
| 88 | info: format!( |
| 89 | "Label entry cannot be longer than {} characters", |
| 90 | AddressBookEntry::MAX_LABEL_LENGTH |
| 91 | ), |
| 92 | }); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if labels.len() > AddressBookEntry::MAX_LABELS { |
| 97 | return Err(AddressBookError::ValidationError { |
| 98 | info: format!( |
| 99 | "Address book entry cannot have more than {} labels", |
| 100 | AddressBookEntry::MAX_LABELS |
| 101 | ), |
| 102 | }); |
| 103 | } |
| 104 | |
| 105 | Ok(()) |
| 106 | } |
| 107 | |
| 108 | impl ModelValidator<AddressBookError> for AddressBookEntry { |
| 109 | fn validate(&self) -> ModelValidatorResult<AddressBookError> { |