@@ -20,15 +20,15 @@ macro_rules! tags {
2020
2121 impl $name {
2222 #[ inline( always) ]
23- fn __from_inner_type( n: $ty) -> Result <Self , $ty> {
23+ const fn __from_inner_type( n: $ty) -> Result <Self , $ty> {
2424 match n {
2525 $( $val => Ok ( $name:: $tag) , ) *
2626 n => Err ( n) ,
2727 }
2828 }
2929
3030 #[ inline( always) ]
31- fn __to_inner_type( & self ) -> $ty {
31+ const fn __to_inner_type( & self ) -> $ty {
3232 match * self {
3333 $( $name:: $tag => $val, ) *
3434 $( $name:: Unknown ( $unknown_doc) => { $unknown_doc } , ) *
@@ -42,19 +42,25 @@ macro_rules! tags {
4242 ( $name: tt, u16 , $( $unknown_doc: ident) * ) => {
4343 impl $name {
4444 #[ inline( always) ]
45- pub fn from_u16( val: u16 ) -> Option <Self > {
46- Self :: __from_inner_type( val) . ok( )
45+ pub const fn from_u16( val: u16 ) -> Option <Self > {
46+ match Self :: __from_inner_type( val) {
47+ Ok ( v) => Some ( v) ,
48+ Err ( _) => None ,
49+ }
4750 }
4851
4952 $(
5053 #[ inline( always) ]
51- pub fn from_u16_exhaustive( $unknown_doc: u16 ) -> Self {
52- Self :: __from_inner_type( $unknown_doc) . unwrap_or_else( |_| $name:: Unknown ( $unknown_doc) )
54+ pub const fn from_u16_exhaustive( $unknown_doc: u16 ) -> Self {
55+ match Self :: __from_inner_type( $unknown_doc) {
56+ Ok ( v) => v,
57+ Err ( _) => $name:: Unknown ( $unknown_doc) ,
58+ }
5359 }
5460 ) *
5561
5662 #[ inline( always) ]
57- pub fn to_u16( & self ) -> u16 {
63+ pub const fn to_u16( & self ) -> u16 {
5864 Self :: __to_inner_type( self )
5965 }
6066 }
0 commit comments