use std::num::{ParseFloatError, ParseIntError};
use crate::sqlx_types::SqlxError;
pub type DiscoveryResult<T> = Result<T, SqliteDiscoveryError>;
#[derive(Debug)]
pub enum SqliteDiscoveryError {
ParseIntError,
ParseFloatError,
IndexNotFound(String),
SqlxError(SqlxError),
}
impl From<ParseIntError> for SqliteDiscoveryError {
fn from(_: ParseIntError) -> Self {
SqliteDiscoveryError::ParseIntError
}
}
impl From<ParseFloatError> for SqliteDiscoveryError {
fn from(_: ParseFloatError) -> Self {
SqliteDiscoveryError::ParseFloatError
}
}
impl From<SqlxError> for SqliteDiscoveryError {
fn from(error: SqlxError) -> Self {
SqliteDiscoveryError::SqlxError(error)
}
}
impl std::error::Error for SqliteDiscoveryError {}
impl std::fmt::Display for SqliteDiscoveryError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
SqliteDiscoveryError::ParseIntError => write!(f, "Parse Integer Error"),
SqliteDiscoveryError::ParseFloatError => write!(f, "Parse Float Error"),
SqliteDiscoveryError::IndexNotFound(index) => write!(f, "Index Not Found: {index}"),
SqliteDiscoveryError::SqlxError(e) => write!(f, "SQLx Error: {e:?}"),
}
}
}