mod db_error;
mod result;
pub use db_error::DbError;
pub(crate) use result::{DbResult, DbResultHelper};
#[macro_export]
macro_rules! db_ensure {
($cond:expr, $msg:literal $(,)?) => {
if !$cond {
return ::core::result::Result::Err($crate::db_error!($msg));
}
};
($cond:expr, $err:expr $(,)?) => {
if !$cond {
return ::core::result::Result::Err($err);
}
};
($cond:expr, $fmt:expr, $($arg:tt)*) => {
if !$cond {
return ::core::result::Result::Err($crate::db_error!($fmt, $($arg)*));
}
};
}
#[macro_export]
macro_rules! db_error {
($msg:literal) => {
$crate::error::DbError::DatabaseError(::core::format_args!($msg).to_string())
};
($err:expr $(,)?) => ({
$crate::error::DbError::DatabaseError($err.to_string())
});
($fmt:expr, $($arg:tt)*) => {
$crate::error::DbError::DatabaseError(::core::format_args!($fmt, $($arg)*).to_string())
};
}
#[macro_export]
macro_rules! db_bail {
($msg:literal) => {
return ::core::result::Result::Err($crate::db_error!($msg))
};
($err:expr $(,)?) => {
return ::core::result::Result::Err($err)
};
($fmt:expr, $($arg:tt)*) => {
return ::core::result::Result::Err($crate::db_error!($fmt, $($arg)*))
};
}