pub trait UrnScheme:
Copy + Clone + PartialEq + Eq + std::hash::Hash + PartialOrd + Ord + std::fmt::Debug + 'static
{
const TASK_PREFIX: &'static str;
const TREE_PREFIX: &'static str;
const VALIDATED: () = {
assert!(
!Self::TASK_PREFIX.is_empty(),
"TASK_PREFIX must not be empty"
);
assert!(
!Self::TREE_PREFIX.is_empty(),
"TREE_PREFIX must not be empty"
);
validate_prefix(Self::TASK_PREFIX);
validate_prefix(Self::TREE_PREFIX);
assert!(
!str_eq(Self::TASK_PREFIX, Self::TREE_PREFIX),
"TASK_PREFIX and TREE_PREFIX must differ"
);
};
}
const fn validate_prefix(prefix: &str) {
let bytes = prefix.as_bytes();
assert!(
bytes[bytes.len() - 1] == b':',
"URN prefixes must end with ':'"
);
let mut index = 0;
while index < bytes.len() {
assert!(
bytes[index].is_ascii_graphic(),
"URN prefixes must be ASCII graphic characters"
);
index += 1;
}
}
const fn str_eq(left: &str, right: &str) -> bool {
let (left, right) = (left.as_bytes(), right.as_bytes());
if left.len() != right.len() {
return false;
}
let mut index = 0;
while index < left.len() {
if left[index] != right[index] {
return false;
}
index += 1;
}
true
}