macro_rules! formats {
{
$(
format = $format:ident
name = $name:literal
media_type = $media_type:literal
extension = $extension:literal
kind = $kind:ident
)*
} => {
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum FileFormat {
$(
#[doc=concat!($name, ".")]
#[doc=concat!("- Media type: `", $media_type, "`")]
#[doc=concat!("- Extension: `", $extension, "`")]
#[doc=concat!("- Kind: [", stringify!($kind), "](`Kind::", stringify!($kind), "`)")]
$format,
)*
}
impl crate::FileFormat {
pub const fn name(&self) -> &str {
match self {
$(
Self::$format => $name,
)*
}
}
pub const fn media_type(&self) -> &str {
match self {
$(
Self::$format => $media_type,
)*
}
}
pub const fn extension(&self) -> &str {
match self {
$(
Self::$format => $extension,
)*
}
}
pub const fn kind(&self) -> crate::Kind {
match self {
$(
Self::$format => crate::Kind::$kind,
)*
}
}
}
};
}
macro_rules! signatures {
{
$(
format = $format:ident
$(value = $($value:literal $(offset = $offset:literal)?),+)+
)*
} => {
impl crate::FileFormat {
pub(crate) fn from_signature(bytes: &[u8]) -> Option<Self> {
$(
if $($(bytes.len() >= $($offset +)? $value.len()
&& &bytes[$($offset)?..$($offset +)? $value.len()] == $value)&&*)||* {
return Some(Self::$format);
}
)*
None
}
}
};
}