MCPcopy Create free account
hub / github.com/dfinity/orbit / validate_labels

Function validate_labels

core/station/impl/src/models/address_book.rs:78–106  ·  view source on GitHub ↗
(labels: &[String])

Source from the content-addressed store, hash-verified

76}
77
78fn 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
108impl ModelValidator<AddressBookError> for AddressBookEntry {
109 fn validate(&self) -> ModelValidatorResult<AddressBookError> {

Callers 1

validateMethod · 0.70

Calls 2

is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected