Tags: generate from_u16_exhaustive for all tags with unknown variants
This commit is contained in:
1 parent
d79d8c3353
commit
0ec8e14910
1 file changed
+11
-9
+11
-9
@@ -39,16 +39,24 @@ macro_rules! tags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tags!($name, $ty);
|
tags!($name, $ty, $($unknown_doc)*);
|
||||||
};
|
};
|
||||||
// For u16 tags, provide direct inherent primitive conversion methods.
|
// For u16 tags, provide direct inherent primitive conversion methods.
|
||||||
($name:tt, u16) => {
|
($name:tt, u16, $($unknown_doc:literal)*) => {
|
||||||
impl $name {
|
impl $name {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn from_u16(val: u16) -> Option<Self> {
|
pub fn from_u16(val: u16) -> Option<Self> {
|
||||||
Self::__from_inner_type(val).ok()
|
Self::__from_inner_type(val).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$(
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn from_u16_exhaustive(val: u16) -> Self {
|
||||||
|
$unknown_doc;
|
||||||
|
Self::__from_inner_type(val).unwrap_or_else(|_| $name::Unknown(val))
|
||||||
|
}
|
||||||
|
)*
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_u16(&self) -> u16 {
|
pub fn to_u16(&self) -> u16 {
|
||||||
Self::__to_inner_type(self)
|
Self::__to_inner_type(self)
|
||||||
@@ -57,7 +65,7 @@ macro_rules! tags {
|
|||||||
};
|
};
|
||||||
// For other tag types, do nothing for now. With concat_idents one could
|
// For other tag types, do nothing for now. With concat_idents one could
|
||||||
// provide inherent conversion methods for all types.
|
// provide inherent conversion methods for all types.
|
||||||
($name:tt, $ty:tt) => {};
|
($name:tt, $ty:tt, $($unknown_doc:literal)*) => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: These tags appear in the order they are mentioned in the TIFF reference
|
// Note: These tags appear in the order they are mentioned in the TIFF reference
|
||||||
@@ -109,12 +117,6 @@ pub enum Tag(u16) unknown("A private or extension tag") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tag {
|
|
||||||
pub fn from_u16_exhaustive(val: u16) -> Self {
|
|
||||||
Self::from_u16(val).unwrap_or_else(|| Tag::Unknown(val))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tags! {
|
tags! {
|
||||||
/// The type of an IFD entry (a 2 byte field).
|
/// The type of an IFD entry (a 2 byte field).
|
||||||
pub enum Type(u16) {
|
pub enum Type(u16) {
|
||||||
|
|||||||
Reference in new issue
Block a user