#[allow(unused)]
use crate::*;
macro_rules! pluralize {
($count:expr) => {
if $count != 1 { "s" } else { "" }
};
}
macro_rules! custom_error_messages_method {
($kind:ident) => {
paste! {
#[inline]
pub fn with_error_messages(
mut self,
error_messages: impl IntoIterator<Item = ([< $kind Violation >], impl Into<FixedStr>)>,
) -> [< $kind ValidatorBuilder >]<SetErrorMessages<S>>
where
S::ErrorMessages: IsUnset,
{
self.data.error_messages = Some(collect_error_messages(error_messages));
[< $kind ValidatorBuilder >] {
_state: PhantomData,
data: self.data,
}
}
}
};
}
#[doc(hidden)]
#[cfg(feature = "inventory")]
#[macro_export]
macro_rules! register_proto_data {
($($tokens:tt)*) => {
$crate::inventory::submit! { $($tokens)* }
};
}
#[doc(hidden)]
#[cfg(not(feature = "inventory"))]
#[macro_export]
macro_rules! register_proto_data {
($($tokens:tt)*) => {};
}
#[macro_export]
macro_rules! proto_option {
( $name:expr => { $($key:expr => $val:expr),* $(,)? } ) => {
$crate::ProtoOption {
name: $name.into(),
value: $crate::OptionValue::Message($crate::option_message!($($key => $val),*)),
}
};
($name:expr => $val:expr) => {
$crate::ProtoOption {
name: $name.into(),
value: $val.into(),
}
};
}
#[macro_export]
macro_rules! option_list {
($list:expr) => {
$crate::OptionValue::new_list($list)
};
}
#[macro_export]
macro_rules! option_message {
($($key:expr => $val:expr),* $(,)?) => {
{
let mut builder = $crate::OptionMessageBuilder::new();
$(
builder.set($key, $val);
)*
builder.build()
}
};
($msg:expr) => {
$crate::OptionValue::new_message($msg)
}
}
macro_rules! length_rule_value {
($name:literal, $value:expr) => {
&LengthRuleValue {
name: $name,
value: $value,
}
};
}
#[macro_export]
macro_rules! inherit_proto_file {
($file:path) => {
#[doc(hidden)]
#[allow(unused)]
const __PROTO_FILE: $crate::FileReference = ::protify::FileReference {
name: <$file as ::protify::FileSchema>::NAME,
package: <$file as ::protify::FileSchema>::PACKAGE,
extern_path: <$file as ::protify::FileSchema>::EXTERN_PATH,
};
};
}
#[macro_export]
macro_rules! use_proto_file {
($file:path) => {
#[doc(hidden)]
#[allow(unused)]
const __PROTO_FILE: $crate::FileReference = ::protify::FileReference {
name: <$file as ::protify::FileSchema>::NAME,
package: <$file as ::protify::FileSchema>::PACKAGE,
extern_path: ::core::module_path!(),
};
};
}
macro_rules! handle_ignore_always {
($ignore:expr) => {
if matches!($ignore, Ignore::Always) {
return Ok(IsValid::Yes);
}
};
}
macro_rules! handle_ignore_if_zero_value {
($ignore:expr, $condition:expr) => {
if matches!($ignore, Ignore::IfZeroValue) && $condition {
return Ok(IsValid::Yes);
}
};
}
macro_rules! impl_testing_methods {
() => {
#[cfg(feature = "cel")]
#[inline(never)]
#[cold]
fn check_cel_programs_with(&self, val: Self::Target) -> Result<(), Vec<CelError>> {
if !self.cel.is_empty() {
test_programs(&self.cel, val)
} else {
Ok(())
}
}
#[cfg(feature = "cel")]
#[inline(never)]
#[cold]
#[doc(hidden)]
fn __check_cel_programs(&self) -> Result<(), Vec<CelError>> {
self.check_cel_programs_with(Self::Target::default())
}
#[doc(hidden)]
#[inline(never)]
#[cold]
fn __cel_rules(&self) -> Vec<CelRule> {
self.cel
.iter()
.map(|p| p.rule().clone())
.collect()
}
};
}
#[macro_export]
macro_rules! cel_program {
(id = $id:expr, msg = $msg:expr, expr = $expr:expr) => {
$crate::CelRule {
id: $id.into(),
message: $msg.into(),
expression: $expr.into(),
}
.into()
};
}
macro_rules! impl_proto_type {
($rust_type:ty, $proto_type:ident) => {
impl AsProtoType for $rust_type {
#[inline]
fn proto_type() -> ProtoType {
ProtoType::Scalar(ProtoScalar::$proto_type)
}
}
};
}
macro_rules! impl_proto_map_key {
($rust_type:ty, $enum_ident:ident) => {
impl AsProtoMapKey for $rust_type {
#[doc(hidden)]
#[allow(private_interfaces)]
const SEALED: crate::Sealed = crate::Sealed;
#[doc(hidden)]
#[cold]
#[inline]
fn as_proto_map_key() -> ProtoMapKey {
ProtoMapKey::$enum_ident
}
}
};
}