diff --git a/src/tags.rs b/src/tags.rs index f456f65..07787d1 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -20,7 +20,7 @@ macro_rules! tags { impl $name { #[inline(always)] - fn __from_inner_type(n: $ty) -> Result { + const fn __from_inner_type(n: $ty) -> Result { match n { $( $val => Ok($name::$tag), )* n => Err(n), @@ -28,7 +28,7 @@ macro_rules! tags { } #[inline(always)] - fn __to_inner_type(&self) -> $ty { + const fn __to_inner_type(&self) -> $ty { match *self { $( $name::$tag => $val, )* $( $name::Unknown($unknown_doc) => { $unknown_doc }, )* @@ -42,19 +42,25 @@ macro_rules! tags { ($name:tt, u16, $($unknown_doc:ident)*) => { impl $name { #[inline(always)] - pub fn from_u16(val: u16) -> Option { - Self::__from_inner_type(val).ok() + pub const fn from_u16(val: u16) -> Option { + match Self::__from_inner_type(val) { + Ok(v) => Some(v), + Err(_) => None, + } } $( #[inline(always)] - pub fn from_u16_exhaustive($unknown_doc: u16) -> Self { - Self::__from_inner_type($unknown_doc).unwrap_or_else(|_| $name::Unknown($unknown_doc)) + pub const fn from_u16_exhaustive($unknown_doc: u16) -> Self { + match Self::__from_inner_type($unknown_doc) { + Ok(v) => v, + Err(_) => $name::Unknown($unknown_doc), + } } )* #[inline(always)] - pub fn to_u16(&self) -> u16 { + pub const fn to_u16(&self) -> u16 { Self::__to_inner_type(self) } }