pub const KIND_MAX_LEN: usize = 128;
pub fn validate_kind(kind: &str) -> Result<(), String> {
if kind.is_empty() {
return Err("kind must not be empty".to_string());
}
if kind.len() > KIND_MAX_LEN {
return Err(format!("kind must not exceed {KIND_MAX_LEN} bytes"));
}
if !kind
.bytes()
.all(|b| b.is_ascii_alphanumeric() || matches!(b, b'.' | b':' | b'_' | b'-'))
{
return Err("kind must contain only ASCII alphanumeric, '.', ':', '_', or '-'".to_string());
}
Ok(())
}
pub fn validate_version(version: i16) -> Result<(), String> {
if version < 1 {
return Err(format!("version must be >= 1, got {version}"));
}
Ok(())
}