#[derive(Debug)]
pub enum GetError {
NotFound,
MultipleObjectsReturned,
Sqlx(sqlx::Error),
}
impl std::fmt::Display for GetError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::NotFound => write!(f, "no matching row"),
Self::MultipleObjectsReturned => {
write!(f, "expected exactly one row, found more")
}
Self::Sqlx(e) => write!(f, "{e}"),
}
}
}
impl std::error::Error for GetError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Sqlx(e) => Some(e),
_ => None,
}
}
}
impl From<sqlx::Error> for GetError {
fn from(e: sqlx::Error) -> Self {
Self::Sqlx(e)
}
}
#[derive(Debug)]
pub enum TryForEachError<E> {
Sqlx(sqlx::Error),
Callback(E),
}
impl<E: std::fmt::Display> std::fmt::Display for TryForEachError<E> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Sqlx(e) => write!(f, "{e}"),
Self::Callback(e) => write!(f, "{e}"),
}
}
}
impl<E: std::fmt::Debug + std::fmt::Display> std::error::Error for TryForEachError<E> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Self::Sqlx(e) => Some(e),
Self::Callback(_) => None,
}
}
}