systemprompt_identifiers/
error.rs

1//! Validation error types for identifiers.
2
3use std::fmt;
4
5#[derive(Debug, Clone)]
6pub enum IdValidationError {
7    Empty {
8        id_type: &'static str,
9    },
10    Invalid {
11        id_type: &'static str,
12        message: String,
13    },
14}
15
16impl fmt::Display for IdValidationError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Self::Empty { id_type } => write!(f, "{} cannot be empty", id_type),
20            Self::Invalid { id_type, message } => write!(f, "{}: {}", id_type, message),
21        }
22    }
23}
24
25impl std::error::Error for IdValidationError {}
26
27impl IdValidationError {
28    #[must_use]
29    pub const fn empty(id_type: &'static str) -> Self {
30        Self::Empty { id_type }
31    }
32
33    #[must_use]
34    pub fn invalid(id_type: &'static str, message: impl Into<String>) -> Self {
35        Self::Invalid {
36            id_type,
37            message: message.into(),
38        }
39    }
40}