Skip to main content

tablo_core/declaration/
area.rs

1//! The declaration mistakes of a panel's [`Area`](crate::Area)s.
2
3use std::fmt;
4
5/// Why an area cannot hold one of the pages auth serves:
6/// [`DeclarationErrorKind::Area`](super::DeclarationErrorKind::Area). Each names the page:
7/// `profile`, `two-factor` or `tenant settings`.
8#[derive(Debug, Clone, PartialEq, Eq)]
9#[non_exhaustive]
10pub enum AreaFault {
11    /// An area holds a page the panel's auth does not install.
12    ///
13    /// Install it on the panel's `Auth`, or take it out of the area.
14    AuthPageNotOffered(&'static str),
15    /// Two groups hold the same page auth serves, which mounts at one URL.
16    ///
17    /// Keep one.
18    AuthPagePlacedTwice(&'static str),
19    /// The def of a page auth serves declares what its page does not render: widgets, filters,
20    /// an access check or header actions.
21    ///
22    /// Drop it from the def.
23    AuthPageDeclares {
24        /// The page.
25        page: &'static str,
26        /// What the def declares.
27        feature: &'static str,
28    },
29}
30
31impl fmt::Display for AreaFault {
32    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
33        match self {
34            Self::AuthPageNotOffered(page) => write!(
35                f,
36                "an area holds the {page} page, which the panel's auth does not install: \
37                 install it on the `Auth`, or take it out of the area"
38            ),
39            Self::AuthPagePlacedTwice(page) => write!(
40                f,
41                "two area groups hold the {page} page, which mounts at one URL: keep one"
42            ),
43            Self::AuthPageDeclares { page, feature } => write!(
44                f,
45                "the def of the {page} page declares {feature}, which the page does not render: \
46                 drop them from the def"
47            ),
48        }
49    }
50}