Skip to main content

semantic_versions/
error.rs

1use std::fmt;
2
3/// Why a version or range failed to parse.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub enum Error {
6    /// The input is longer than [`MAX_LENGTH`](crate::MAX_LENGTH).
7    TooLong,
8    /// The input is not a valid version.
9    InvalidVersion(String),
10    /// A numeric identifier exceeds [`MAX_SAFE_INTEGER`](crate::MAX_SAFE_INTEGER).
11    TooLarge(String),
12    /// The input is not a valid range.
13    InvalidRange(String),
14}
15
16impl fmt::Display for Error {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            Error::TooLong => write!(f, "input is longer than {} characters", crate::MAX_LENGTH),
20            Error::InvalidVersion(s) => write!(f, "invalid version: {s}"),
21            Error::TooLarge(s) => write!(f, "numeric identifier is too large: {s}"),
22            Error::InvalidRange(s) => write!(f, "invalid range: {s}"),
23        }
24    }
25}
26
27impl std::error::Error for Error {}