tablo_core/declaration/serve_dir.rs
1//! Why a panel cannot serve a directory.
2
3use std::fmt;
4
5/// Why a panel cannot serve a directory [`serve_dir`](crate::Panel::serve_dir) or
6/// [`uploads_dir`](crate::Panel::uploads_dir) declares.
7#[derive(Debug, Clone, PartialEq, Eq)]
8#[non_exhaustive]
9pub enum ServeDirFault {
10 /// A pattern that does not end in a catch-all.
11 ///
12 /// End it in `{*file}`: `/uploads/{*file}`.
13 WithoutCatchAll {
14 /// The pattern.
15 path: String,
16 },
17 /// The panel serves the same directory pattern twice.
18 ///
19 /// Drop the second `serve_dir`.
20 Twice {
21 /// The pattern.
22 path: String,
23 },
24 /// Another panel already serves the directory pattern.
25 ///
26 /// Serve it from one panel.
27 Taken {
28 /// The pattern.
29 path: String,
30 /// The serving panel's prefix.
31 panel: String,
32 },
33}
34
35impl fmt::Display for ServeDirFault {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 match self {
38 Self::WithoutCatchAll { path } => write!(
39 f,
40 "serve_dir path '{path}' must end in a catch-all like '/uploads/{{*file}}'"
41 ),
42 Self::Twice { path } => write!(f, "serve_dir path '{path}' is declared twice"),
43 Self::Taken { path, panel } => write!(
44 f,
45 "serve_dir path '{path}' is already served by the panel mounted at '{panel}'"
46 ),
47 }
48 }
49}