Skip to main content

custom_string/
validation_error.rs

1/// An error validating the value of a custom string.
2#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, 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
16impl ValidationError {
17    //! Properties
18
19    /// Gets the message.
20    pub fn message(self) -> &'static str {
21        self.message
22    }
23}
24
25impl std::fmt::Display for ValidationError {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        write!(f, "{}", self.message)
28    }
29}
30
31impl std::error::Error for ValidationError {}