mod request;
mod response;
pub use request::{Condition, ConditionMatch};
pub use response::{ResponseCondition, ResponseConditionMatch};
macro_rules! impl_condition_deserialize {
($cond:ident, $match_:ty, $label:expr) => {
#[derive(serde::Deserialize)]
struct ConditionDeserHelper {
#[serde(default)]
when: Option<$match_>,
#[serde(default)]
unless: Option<$match_>,
}
impl<'de> serde::Deserialize<'de> for $cond {
fn deserialize<D: serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let helper = ConditionDeserHelper::deserialize(deserializer)?;
match (helper.when, helper.unless) {
(Some(m), None) => Ok($cond::When(m)),
(None, Some(m)) => Ok($cond::Unless(m)),
(Some(_), Some(_)) => Err(serde::de::Error::custom(concat!(
$label,
" must have exactly one of 'when' or 'unless', not both"
))),
(None, None) => Err(serde::de::Error::custom(concat!(
$label,
" must have either 'when' or 'unless'"
))),
}
}
}
};
}
pub(crate) use impl_condition_deserialize;