mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-02 04:04:43 +08:00
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Sai Harsha Vardhan <56996463+sai-harsha-vardhan@users.noreply.github.com> Co-authored-by: Sahkal Poddar <sahkalplanet@gmail.com> Co-authored-by: Amisha Prabhat <55580080+Aprabhat19@users.noreply.github.com> Co-authored-by: Sarthak Soni <76486416+Sarthak1799@users.noreply.github.com> Co-authored-by: shashank_attarde <shashank.attarde@juspay.in> Co-authored-by: Aprabhat19 <amishaprabhat@gmail.com> Co-authored-by: sai-harsha-vardhan <harsha111hero@gmail.com> Co-authored-by: Sahkal Poddar <sahkal.poddar@juspay.in> Co-authored-by: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com>
105 lines
2.6 KiB
Rust
105 lines
2.6 KiB
Rust
#![allow(missing_docs)]
|
|
|
|
#[macro_export]
|
|
macro_rules! newtype_impl {
|
|
($is_pub:vis, $name:ident, $ty_path:path) => {
|
|
impl std::ops::Deref for $name {
|
|
type Target = $ty_path;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl std::ops::DerefMut for $name {
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
&mut self.0
|
|
}
|
|
}
|
|
|
|
impl From<$ty_path> for $name {
|
|
fn from(ty: $ty_path) -> Self {
|
|
Self(ty)
|
|
}
|
|
}
|
|
|
|
impl $name {
|
|
pub fn into_inner(self) -> $ty_path {
|
|
self.0
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! newtype {
|
|
($is_pub:vis $name:ident = $ty_path:path) => {
|
|
$is_pub struct $name(pub $ty_path);
|
|
|
|
$crate::newtype_impl!($is_pub, $name, $ty_path);
|
|
};
|
|
|
|
($is_pub:vis $name:ident = $ty_path:path, derives = ($($trt:path),*)) => {
|
|
#[derive($($trt),*)]
|
|
$is_pub struct $name(pub $ty_path);
|
|
|
|
$crate::newtype_impl!($is_pub, $name, $ty_path);
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! async_spawn {
|
|
($t:block) => {
|
|
tokio::spawn(async move { $t });
|
|
};
|
|
}
|
|
|
|
/// Use this to ensure that the corresponding
|
|
/// openapi route has been implemented in the openapi crate
|
|
#[macro_export]
|
|
macro_rules! openapi_route {
|
|
($route_name: ident) => {{
|
|
#[cfg(feature = "openapi")]
|
|
use openapi::routes::$route_name as _;
|
|
|
|
$route_name
|
|
}};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! fallback_reverse_lookup_not_found {
|
|
($a:expr,$b:expr) => {
|
|
match $a {
|
|
Ok(res) => res,
|
|
Err(err) => {
|
|
router_env::logger::error!(reverse_lookup_fallback = %err);
|
|
match err.current_context() {
|
|
errors::StorageError::ValueNotFound(_) => return $b,
|
|
errors::StorageError::DatabaseError(data_err) => {
|
|
match data_err.current_context() {
|
|
diesel_models::errors::DatabaseError::NotFound => return $b,
|
|
_ => return Err(err)
|
|
}
|
|
}
|
|
_=> return Err(err)
|
|
}
|
|
}
|
|
};
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! collect_missing_value_keys {
|
|
[$(($key:literal, $option:expr)),+] => {
|
|
{
|
|
let mut keys: Vec<&'static str> = Vec::new();
|
|
$(
|
|
if $option.is_none() {
|
|
keys.push($key);
|
|
}
|
|
)*
|
|
keys
|
|
}
|
|
};
|
|
}
|