macro_rules! model_id_table {
(
$(
$variant:ident {
provider: $provider:ident,
id: $id:expr,
$( parse: [ $( $parse:expr ),* $(,)? ], )?
display: $display:expr,
description: $description:expr $(,)?
}
),* $(,)?
) => {
impl ModelId {
pub(super) fn table_id(&self) -> Option<&'static str> {
match self {
$( ModelId::$variant => Some($id), )*
_ => None,
}
}
pub(super) fn table_display(&self) -> Option<&'static str> {
match self {
$( ModelId::$variant => Some($display), )*
_ => None,
}
}
pub(super) fn table_description(&self) -> Option<&'static str> {
match self {
$( ModelId::$variant => Some($description), )*
_ => None,
}
}
pub(super) fn table_provider(&self) -> Option<Provider> {
match self {
$( ModelId::$variant => Some(Provider::$provider), )*
_ => None,
}
}
pub(super) fn parse_table(s: &str) -> Option<ModelId> {
$(
$( $( if s == $parse { return Some(ModelId::$variant); } )* )*
model_id_table!(@default_parse s, $variant, $id $(, [$($parse),*] )? );
)*
None
}
}
};
(@default_parse $s:ident, $variant:ident, $id:expr) => {
if $s == $id { return Some(ModelId::$variant); }
};
(@default_parse $s:ident, $variant:ident, $id:expr, []) => {
let _ = ($s, $id);
};
(@default_parse $s:ident, $variant:ident, $id:expr, [$($parse:expr),+ $(,)?]) => {
let _ = ($s, $id);
};
}