mod format;
mod layout;
mod props;
mod reload;
mod schema;
mod theme;
mod value;
use std::fmt;
pub use format::to_form_text;
pub use layout::{load, load_value, save, save_value, validate};
pub use props::{prop_from_json, prop_to_json, set_props};
pub use reload::{ReloadReport, reload};
pub use schema::{catalog, catalog_enums_test, class_info, schema};
pub use serde_json;
pub use theme::{load_theme, save_theme, theme_from_value, theme_to_value};
pub const FORMAT_VERSION: u64 = 1;
#[derive(Debug)]
pub enum Error {
Json(serde_json::Error),
Version(u64),
Structure { path: String, message: String },
Property { path: String, property: String, message: String },
Component { path: String, source: aylis_core::Error },
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Json(e) => write!(f, "JSON inválido: {e}"),
Error::Version(v) => {
if *v > FORMAT_VERSION {
write!(f, "formato {v} é mais novo que este aylis (que lê o {FORMAT_VERSION}): atualize o aylis")
} else {
write!(f, "formato {v} é de uma versão anterior do Aylis (este lê o {FORMAT_VERSION}): rode o aylis-migrate no projeto")
}
}
Error::Structure { path, message } => write!(f, "{}{message}", at(path)),
Error::Property { path, property, message } => {
write!(f, "{}propriedade '{property}': {message}", at(path))
}
Error::Component { path, source } => write!(f, "{}{source}", at(path)),
}
}
}
fn at(path: &str) -> String {
if path.is_empty() { String::new() } else { format!("{path}: ") }
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Json(e) => Some(e),
Error::Component { source, .. } => Some(source),
_ => None,
}
}
}
impl From<serde_json::Error> for Error {
fn from(e: serde_json::Error) -> Self {
Error::Json(e)
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;