Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit 335bcd5

Browse files
committed
feat: use constrained trait instead of own impl
1 parent 214989c commit 335bcd5

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/types/federation_id.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,11 @@ pub struct DomainName {
3838
impl DomainName {
3939
/// Validates input, then creates a new [DomainName].
4040
pub fn new(domain_name: &str) -> Result<Self, ConstraintError> {
41-
#[allow(clippy::unwrap_used)]
42-
let regex = Regex::new(REGEX_DOMAIN_NAME).unwrap();
43-
if regex.is_match(domain_name) {
44-
Ok(Self {
45-
value: domain_name.to_string(),
46-
})
47-
} else {
48-
Err(ConstraintError::Malformed(Some(String::from(
49-
"Supplied domain name does not match regex",
50-
))))
51-
}
41+
let dn = Self {
42+
value: domain_name.to_string(),
43+
};
44+
dn.validate(None)?;
45+
Ok(dn)
5246
}
5347
}
5448

0 commit comments

Comments
 (0)