Skip to main content

qubit_case/
case_style_error.rs

1// =============================================================================
2//    Copyright (c) 2025 - 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8//! # Case Style Errors
9//!
10//! Defines errors returned when parsing case style names.
11
12use std::fmt;
13
14/// Error returned when a case style name is unknown.
15#[derive(Debug, Clone, PartialEq, Eq)]
16pub struct CaseStyleError {
17    name: String,
18}
19
20impl CaseStyleError {
21    /// Creates an unknown case style error.
22    ///
23    /// # Parameters
24    ///
25    /// * `name` - Original style name that could not be parsed.
26    ///
27    /// # Returns
28    ///
29    /// Returns a new error carrying the original name.
30    #[inline]
31    pub fn new(name: impl Into<String>) -> Self {
32        Self { name: name.into() }
33    }
34
35    /// Returns the unknown naming style name.
36    ///
37    /// # Returns
38    ///
39    /// Returns the original name passed to `CaseStyle::of` or `FromStr`.
40    #[inline]
41    pub fn name(&self) -> &str {
42        &self.name
43    }
44}
45
46impl fmt::Display for CaseStyleError {
47    /// Formats the unknown naming style error.
48    ///
49    /// # Parameters
50    ///
51    /// * `f` - Formatter receiving the message.
52    ///
53    /// # Returns
54    ///
55    /// Returns the formatter result.
56    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57        write!(f, "Unknown case style: '{}'.", self.name)
58    }
59}
60
61impl std::error::Error for CaseStyleError {}