Skip to main content

custom_string/
validation_error.rs

1/// An error validating the value of a custom string.
2#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
3pub struct ValidationError {
4    message: &'static str,
5}
6
7impl ValidationError {
8    //! Construction
9
10    /// Creates a new error with the given `message`.
11    pub fn new(message: &'static str) -> Self {
12        Self { message }
13    }
14
15    /// Gets the error message.
16    pub fn message(&self) -> &'static str {
17        self.message
18    }
19}
20
21impl std::fmt::Display for ValidationError {
22    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23        write!(f, "{}", self.message)
24    }
25}
26
27impl std::error::Error for ValidationError {}