macro_rules! non_auth_subclass {
($enum:ident @ $class:ident: {$($var:ident: $id:literal, $public_name:literal;)*}) => {
#[doc = concat!("Enum for all known subclasses of the ", class_doc_public_name!($class)," device class")]
#[cfg_attr(feature = "fixed-repr", repr(u16))]
#[non_exhaustive]
pub enum $enum{
$(#[doc = concat!("The ", $public_name, " subclass")] $var = $id),*
}
impl core::convert::From<$enum> for crate::SubclassId{
fn from(x: $enum) -> Self{
x.into_generic()
}
}
impl $enum{
#[doc = concat!("Returns the numeric id associated with the [`", stringify!($enum),"`].")]
pub const fn id(&self) -> u16{
match self{
$(Self:: $var => $id),*
}
}
#[doc = concat!("Returns the [`", stringify!($enum),"`] associated with the given id if it exists, or otherwise returns `None`.")]
pub const fn from_id(id: u16) -> Option<Self>{
match id{
$($id => Some(Self:: $var),)*
_ => None
}
}
#[doc = concat!("Converts the [`", stringify!($enum),"`] into a [`SubclassId`][crate::SubclassId]")]
pub const fn into_generic(self) -> crate::SubclassId{
crate::SubclassId::from_id(self.id())
}
#[cfg(feature = "extended-info")]
#[doc = concat!("Retrieves the public (display) name from the registration associated with this [`", stringify!($enum), "`].")]
pub const fn public_name(&self) -> &'static str{
match self{
$(Self:: $var => $public_name),*
}
}
}
}
}
macro_rules! non_auth_product {
($enum:ident @ $class:ident: {$($var:ident: $id:literal, $public_name:literal;)*}) => {
#[doc = concat!("Enum for all known products of the ", vendor_doc_public_name!($class)," vendor")]
#[cfg_attr(feature = "fixed-repr", repr(u16))]
#[non_exhaustive]
pub enum $enum{
$(#[doc = concat!("The ", $public_name, " product")] $var = $id),*
}
impl core::convert::From<$enum> for crate::ProductId{
fn from(x: $enum) -> Self{
x.into_generic()
}
}
impl $enum{
#[doc = concat!("Returns the numeric id associated with the [`", stringify!($enum),"`].")]
pub const fn id(&self) -> u16{
match self{
$(Self:: $var => $id),*
}
}
#[doc = concat!("Returns the [`", stringify!($enum),"`] associated with the given id if it exists, or otherwise returns `None`.")]
pub const fn from_id(id: u16) -> Option<Self>{
match id{
$($id => Some(Self:: $var),)*
_ => None
}
}
#[doc = concat!("Converts the [`", stringify!($enum),"`] into a [`ProductId`][crate::ProductId]")]
pub const fn into_generic(self) -> crate::ProductId{
crate::ProductId::from_id(self.id())
}
#[cfg(feature = "extended-info")]
#[doc = concat!("Retrieves the public (display) name from the registration associated with this [`", stringify!($enum), "`].")]
pub const fn public_name(&self) -> &'static str{
match self{
$(Self:: $var => $public_name),*
}
}
}
}
}
macro_rules! classes {
($($var:ident: $id:literal, $public_name:literal, $subclass_registry_owner:literal, $registrar:literal;)*) => {
macro_rules! class_doc_public_name{
$(($var) => {$public_name};)*
}
};
}
macro_rules! vendors {
($($var:ident: $id:literal, $public_name:literal, $vendor_registry_owner:literal, $registrar:literal;)*) => {
macro_rules! vendor_doc_public_name{
$(($var) => {$public_name};)*
}
};
}
macro_rules! well_known_subclass {
($enum:ident @ $class:ident: {$($var:ident: $id:literal, $public_name:literal, $specification:literal, $registrar:literal;)*}) => {};
}
include!(env!("TABLES_GENERATED"));
include!(env!("NON_AUTH_TABLES_GENERATED"));