1mod format;
34mod layout;
35mod props;
36mod reload;
37mod schema;
38mod theme;
39mod value;
40
41use std::fmt;
42
43pub use format::to_form_text;
44pub use layout::{load, load_value, save, save_value, validate};
45pub use props::{prop_from_json, prop_to_json, set_props};
46pub use reload::{ReloadReport, reload};
47pub use schema::{catalog, catalog_enums_test, class_info, schema};
48pub use serde_json;
50pub use theme::{load_theme, save_theme, theme_from_value, theme_to_value};
51
52pub const FORMAT_VERSION: u64 = 1;
54
55#[derive(Debug)]
57pub enum Error {
58 Json(serde_json::Error),
60 Version(u64),
62 Structure { path: String, message: String },
64 Property { path: String, property: String, message: String },
66 Component { path: String, source: aylis_core::Error },
68}
69
70impl fmt::Display for Error {
71 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72 match self {
73 Error::Json(e) => write!(f, "JSON inválido: {e}"),
74 Error::Version(v) => {
75 if *v > FORMAT_VERSION {
76 write!(f, "formato {v} é mais novo que este aylis (que lê o {FORMAT_VERSION}): atualize o aylis")
77 } else {
78 write!(f, "formato {v} é de uma versão anterior do Aylis (este lê o {FORMAT_VERSION}): rode o aylis-migrate no projeto")
79 }
80 }
81 Error::Structure { path, message } => write!(f, "{}{message}", at(path)),
82 Error::Property { path, property, message } => {
83 write!(f, "{}propriedade '{property}': {message}", at(path))
84 }
85 Error::Component { path, source } => write!(f, "{}{source}", at(path)),
86 }
87 }
88}
89
90fn at(path: &str) -> String {
91 if path.is_empty() { String::new() } else { format!("{path}: ") }
92}
93
94impl std::error::Error for Error {
95 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
96 match self {
97 Error::Json(e) => Some(e),
98 Error::Component { source, .. } => Some(source),
99 _ => None,
100 }
101 }
102}
103
104impl From<serde_json::Error> for Error {
105 fn from(e: serde_json::Error) -> Self {
106 Error::Json(e)
107 }
108}
109
110pub type Result<T, E = Error> = std::result::Result<T, E>;