use std::error::Error as StdError;
use std::fmt;
#[derive(Debug)]
pub enum Error {
ModelDefinition(String),
Adapter(String),
SqlGeneration(String),
UnsupportedFeature(String),
Other(String),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::ModelDefinition(msg) => write!(f, "Model definition error: {}", msg),
Error::Adapter(msg) => write!(f, "Adapter error: {}", msg),
Error::SqlGeneration(msg) => write!(f, "SQL generation error: {}", msg),
Error::UnsupportedFeature(msg) => write!(f, "Unsupported feature: {}", msg),
Error::Other(msg) => write!(f, "Error: {}", msg),
}
}
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
None
}
}
pub type Result<T> = std::result::Result<T, Error>;
pub fn model_definition_error<S: Into<String>>(msg: S) -> Error {
Error::ModelDefinition(msg.into())
}
pub fn adapter_error<S: Into<String>>(msg: S) -> Error {
Error::Adapter(msg.into())
}
pub fn sql_generation_error<S: Into<String>>(msg: S) -> Error {
Error::SqlGeneration(msg.into())
}
pub fn unsupported_feature_error<S: Into<String>>(msg: S) -> Error {
Error::UnsupportedFeature(msg.into())
}
pub fn other_error<S: Into<String>>(msg: S) -> Error {
Error::Other(msg.into())
}