use thiserror::Error; #[derive(Debug, Error, PartialEq, Eq)] pub enum IdError { #[error("a workspace ID must contain 1–96 bytes and no NUL")] Workspace, #[error("a document ID must contain 1–128 bytes and no NUL")] Document, #[error("a user ID must contain 1–128 bytes and no NUL")] User, #[error("an organization ID must contain 1–128 bytes and no NUL")] Organization, } pub(super) fn validate_id(value: &str, max_bytes: usize, error: IdError) -> Result<(), IdError> { if value.is_empty() || value.len() > max_bytes || value.contains('\0') { return Err(error); } Ok(()) }