arch_pkg_db/value/
repository.rs

1use derive_more::{AsRef, Deref, Display, From, Into};
2
3/// Name of a repository.
4#[derive(Debug, Display, Clone, Copy, PartialEq, Eq, AsRef, Deref, From, Into)]
5pub struct RepositoryName<'a>(pub &'a str);
6
7impl<'a> RepositoryName<'a> {
8    /// Get an immutable reference to the string underneath.
9    pub fn as_str(&self) -> &'a str {
10        self.0
11    }
12
13    /// Whether this name is a valid name.
14    pub fn is_valid(&self) -> bool {
15        let valid_char = |char| matches!(char, 'a'..='z' | 'A'..='Z' | '0'..='9' | '_' | '-' | '.');
16        !self.is_empty() && self.chars().all(valid_char)
17    }
18}