Skip to main content

owl_structural_model/
error.rs

1//! Errors raised by structural constructors.
2
3use std::fmt::{Display, Formatter};
4
5/// A structural value failed an invariant at construction time.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum StructuralModelError {
8    /// A required value was empty.
9    Empty {
10        /// The kind of value that was empty.
11        kind: &'static str,
12    },
13    /// A value had the wrong structural shape.
14    InvalidFormat {
15        /// The kind of value that was invalid.
16        kind: &'static str,
17        /// The supplied representation.
18        value: String,
19        /// The required shape.
20        message: &'static str,
21    },
22}
23
24impl Display for StructuralModelError {
25    fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
26        match self {
27            Self::Empty { kind } => write!(formatter, "{kind} must not be empty"),
28            Self::InvalidFormat {
29                kind,
30                value,
31                message,
32            } => write!(formatter, "invalid {kind}: {message} (got: {value})"),
33        }
34    }
35}
36
37impl std::error::Error for StructuralModelError {}