diff --git a/src/enum_impl/i8_repr.rs b/src/enum_impl/i8_repr.rs new file mode 100644 index 0000000..0f544da --- /dev/null +++ b/src/enum_impl/i8_repr.rs @@ -0,0 +1,521 @@ +#[derive(Clone, Copy, PartialEq, Eq, Hash)] +pub(crate) enum I8ByteRepr { + V0 = 0, + V1 = 1, + V2 = 2, + V3 = 3, + V4 = 4, + V5 = 5, + V6 = 6, + V7 = 7, + V8 = 8, + V9 = 9, + V10 = 10, + V11 = 11, + V12 = 12, + V13 = 13, + V14 = 14, + V15 = 15, + V16 = 16, + V17 = 17, + V18 = 18, + V19 = 19, + V20 = 20, + V21 = 21, + V22 = 22, + V23 = 23, + V24 = 24, + V25 = 25, + V26 = 26, + V27 = 27, + V28 = 28, + V29 = 29, + V30 = 30, + V31 = 31, + V32 = 32, + V33 = 33, + V34 = 34, + V35 = 35, + V36 = 36, + V37 = 37, + V38 = 38, + V39 = 39, + V40 = 40, + V41 = 41, + V42 = 42, + V43 = 43, + V44 = 44, + V45 = 45, + V46 = 46, + V47 = 47, + V48 = 48, + V49 = 49, + V50 = 50, + V51 = 51, + V52 = 52, + V53 = 53, + V54 = 54, + V55 = 55, + V56 = 56, + V57 = 57, + V58 = 58, + V59 = 59, + V60 = 60, + V61 = 61, + V62 = 62, + V63 = 63, + V64 = 64, + V65 = 65, + V66 = 66, + V67 = 67, + V68 = 68, + V69 = 69, + V70 = 70, + V71 = 71, + V72 = 72, + V73 = 73, + V74 = 74, + V75 = 75, + V76 = 76, + V77 = 77, + V78 = 78, + V79 = 79, + V80 = 80, + V81 = 81, + V82 = 82, + V83 = 83, + V84 = 84, + V85 = 85, + V86 = 86, + V87 = 87, + V88 = 88, + V89 = 89, + V90 = 90, + V91 = 91, + V92 = 92, + V93 = 93, + V94 = 94, + V95 = 95, + V96 = 96, + V97 = 97, + V98 = 98, + V99 = 99, + V100 = 100, + V101 = 101, + V102 = 102, + V103 = 103, + V104 = 104, + V105 = 105, + V106 = 106, + V107 = 107, + V108 = 108, + V109 = 109, + V110 = 110, + V111 = 111, + V112 = 112, + V113 = 113, + V114 = 114, + V115 = 115, + V116 = 116, + V117 = 117, + V118 = 118, + V119 = 119, + V120 = 120, + V121 = 121, + V122 = 122, + V123 = 123, + V124 = 124, + V125 = 125, + V126 = 126, + MV127 = -128, + MV128 = -127, + MV129 = -126, + MV130 = -125, + MV131 = -124, + MV132 = -123, + MV133 = -122, + MV134 = -121, + MV135 = -120, + MV136 = -119, + MV137 = -118, + MV138 = -117, + MV139 = -116, + MV140 = -115, + MV141 = -114, + MV142 = -113, + MV143 = -112, + MV144 = -111, + MV145 = -110, + MV146 = -109, + MV147 = -108, + MV148 = -107, + MV149 = -106, + MV150 = -105, + MV151 = -104, + MV152 = -103, + MV153 = -102, + MV154 = -101, + MV155 = -100, + MV156 = -99, + MV157 = -98, + MV158 = -97, + MV159 = -96, + MV160 = -95, + MV161 = -94, + MV162 = -93, + MV163 = -92, + MV164 = -91, + MV165 = -90, + MV166 = -89, + MV167 = -88, + MV168 = -87, + MV169 = -86, + MV170 = -85, + MV171 = -84, + MV172 = -83, + MV173 = -82, + MV174 = -81, + MV175 = -80, + MV176 = -79, + MV177 = -78, + MV178 = -77, + MV179 = -76, + MV180 = -75, + MV181 = -74, + MV182 = -73, + MV183 = -72, + MV184 = -71, + MV185 = -70, + MV186 = -69, + MV187 = -68, + MV188 = -67, + MV189 = -66, + MV190 = -65, + MV191 = -64, + MV192 = -63, + MV193 = -62, + MV194 = -61, + MV195 = -60, + MV196 = -59, + MV197 = -58, + MV198 = -57, + MV199 = -56, + MV200 = -55, + MV201 = -54, + MV202 = -53, + MV203 = -52, + MV204 = -51, + MV205 = -50, + MV206 = -49, + MV207 = -48, + MV208 = -47, + MV209 = -46, + MV210 = -45, + MV211 = -44, + MV212 = -43, + MV213 = -42, + MV214 = -41, + MV215 = -40, + MV216 = -39, + MV217 = -38, + MV218 = -37, + MV219 = -36, + MV220 = -35, + MV221 = -34, + MV222 = -33, + MV223 = -32, + MV224 = -31, + MV225 = -30, + MV226 = -29, + MV227 = -28, + MV228 = -27, + MV229 = -26, + MV230 = -25, + MV231 = -24, + MV232 = -23, + MV233 = -22, + MV234 = -21, + MV235 = -20, + MV236 = -19, + MV237 = -18, + MV238 = -17, + MV239 = -16, + MV240 = -15, + MV241 = -14, + MV242 = -13, + MV243 = -12, + MV244 = -11, + MV245 = -10, + MV246 = -9, + MV247 = -8, + MV248 = -7, + MV249 = -6, + MV250 = -5, + MV251 = -4, + MV252 = -3, + MV253 = -2, + MV254 = -1, +} + +impl I8ByteRepr { + pub const fn new(value: i8) -> Option { + match value { + 0 => Some(Self::V0), + 1 => Some(Self::V1), + 2 => Some(Self::V2), + 3 => Some(Self::V3), + 4 => Some(Self::V4), + 5 => Some(Self::V5), + 6 => Some(Self::V6), + 7 => Some(Self::V7), + 8 => Some(Self::V8), + 9 => Some(Self::V9), + 10 => Some(Self::V10), + 11 => Some(Self::V11), + 12 => Some(Self::V12), + 13 => Some(Self::V13), + 14 => Some(Self::V14), + 15 => Some(Self::V15), + 16 => Some(Self::V16), + 17 => Some(Self::V17), + 18 => Some(Self::V18), + 19 => Some(Self::V19), + 20 => Some(Self::V20), + 21 => Some(Self::V21), + 22 => Some(Self::V22), + 23 => Some(Self::V23), + 24 => Some(Self::V24), + 25 => Some(Self::V25), + 26 => Some(Self::V26), + 27 => Some(Self::V27), + 28 => Some(Self::V28), + 29 => Some(Self::V29), + 30 => Some(Self::V30), + 31 => Some(Self::V31), + 32 => Some(Self::V32), + 33 => Some(Self::V33), + 34 => Some(Self::V34), + 35 => Some(Self::V35), + 36 => Some(Self::V36), + 37 => Some(Self::V37), + 38 => Some(Self::V38), + 39 => Some(Self::V39), + 40 => Some(Self::V40), + 41 => Some(Self::V41), + 42 => Some(Self::V42), + 43 => Some(Self::V43), + 44 => Some(Self::V44), + 45 => Some(Self::V45), + 46 => Some(Self::V46), + 47 => Some(Self::V47), + 48 => Some(Self::V48), + 49 => Some(Self::V49), + 50 => Some(Self::V50), + 51 => Some(Self::V51), + 52 => Some(Self::V52), + 53 => Some(Self::V53), + 54 => Some(Self::V54), + 55 => Some(Self::V55), + 56 => Some(Self::V56), + 57 => Some(Self::V57), + 58 => Some(Self::V58), + 59 => Some(Self::V59), + 60 => Some(Self::V60), + 61 => Some(Self::V61), + 62 => Some(Self::V62), + 63 => Some(Self::V63), + 64 => Some(Self::V64), + 65 => Some(Self::V65), + 66 => Some(Self::V66), + 67 => Some(Self::V67), + 68 => Some(Self::V68), + 69 => Some(Self::V69), + 70 => Some(Self::V70), + 71 => Some(Self::V71), + 72 => Some(Self::V72), + 73 => Some(Self::V73), + 74 => Some(Self::V74), + 75 => Some(Self::V75), + 76 => Some(Self::V76), + 77 => Some(Self::V77), + 78 => Some(Self::V78), + 79 => Some(Self::V79), + 80 => Some(Self::V80), + 81 => Some(Self::V81), + 82 => Some(Self::V82), + 83 => Some(Self::V83), + 84 => Some(Self::V84), + 85 => Some(Self::V85), + 86 => Some(Self::V86), + 87 => Some(Self::V87), + 88 => Some(Self::V88), + 89 => Some(Self::V89), + 90 => Some(Self::V90), + 91 => Some(Self::V91), + 92 => Some(Self::V92), + 93 => Some(Self::V93), + 94 => Some(Self::V94), + 95 => Some(Self::V95), + 96 => Some(Self::V96), + 97 => Some(Self::V97), + 98 => Some(Self::V98), + 99 => Some(Self::V99), + 100 => Some(Self::V100), + 101 => Some(Self::V101), + 102 => Some(Self::V102), + 103 => Some(Self::V103), + 104 => Some(Self::V104), + 105 => Some(Self::V105), + 106 => Some(Self::V106), + 107 => Some(Self::V107), + 108 => Some(Self::V108), + 109 => Some(Self::V109), + 110 => Some(Self::V110), + 111 => Some(Self::V111), + 112 => Some(Self::V112), + 113 => Some(Self::V113), + 114 => Some(Self::V114), + 115 => Some(Self::V115), + 116 => Some(Self::V116), + 117 => Some(Self::V117), + 118 => Some(Self::V118), + 119 => Some(Self::V119), + 120 => Some(Self::V120), + 121 => Some(Self::V121), + 122 => Some(Self::V122), + 123 => Some(Self::V123), + 124 => Some(Self::V124), + 125 => Some(Self::V125), + 126 => Some(Self::V126), + 127 => None, + -128 => Some(Self::MV127), + -127 => Some(Self::MV128), + -126 => Some(Self::MV129), + -125 => Some(Self::MV130), + -124 => Some(Self::MV131), + -123 => Some(Self::MV132), + -122 => Some(Self::MV133), + -121 => Some(Self::MV134), + -120 => Some(Self::MV135), + -119 => Some(Self::MV136), + -118 => Some(Self::MV137), + -117 => Some(Self::MV138), + -116 => Some(Self::MV139), + -115 => Some(Self::MV140), + -114 => Some(Self::MV141), + -113 => Some(Self::MV142), + -112 => Some(Self::MV143), + -111 => Some(Self::MV144), + -110 => Some(Self::MV145), + -109 => Some(Self::MV146), + -108 => Some(Self::MV147), + -107 => Some(Self::MV148), + -106 => Some(Self::MV149), + -105 => Some(Self::MV150), + -104 => Some(Self::MV151), + -103 => Some(Self::MV152), + -102 => Some(Self::MV153), + -101 => Some(Self::MV154), + -100 => Some(Self::MV155), + -99 => Some(Self::MV156), + -98 => Some(Self::MV157), + -97 => Some(Self::MV158), + -96 => Some(Self::MV159), + -95 => Some(Self::MV160), + -94 => Some(Self::MV161), + -93 => Some(Self::MV162), + -92 => Some(Self::MV163), + -91 => Some(Self::MV164), + -90 => Some(Self::MV165), + -89 => Some(Self::MV166), + -88 => Some(Self::MV167), + -87 => Some(Self::MV168), + -86 => Some(Self::MV169), + -85 => Some(Self::MV170), + -84 => Some(Self::MV171), + -83 => Some(Self::MV172), + -82 => Some(Self::MV173), + -81 => Some(Self::MV174), + -80 => Some(Self::MV175), + -79 => Some(Self::MV176), + -78 => Some(Self::MV177), + -77 => Some(Self::MV178), + -76 => Some(Self::MV179), + -75 => Some(Self::MV180), + -74 => Some(Self::MV181), + -73 => Some(Self::MV182), + -72 => Some(Self::MV183), + -71 => Some(Self::MV184), + -70 => Some(Self::MV185), + -69 => Some(Self::MV186), + -68 => Some(Self::MV187), + -67 => Some(Self::MV188), + -66 => Some(Self::MV189), + -65 => Some(Self::MV190), + -64 => Some(Self::MV191), + -63 => Some(Self::MV192), + -62 => Some(Self::MV193), + -61 => Some(Self::MV194), + -60 => Some(Self::MV195), + -59 => Some(Self::MV196), + -58 => Some(Self::MV197), + -57 => Some(Self::MV198), + -56 => Some(Self::MV199), + -55 => Some(Self::MV200), + -54 => Some(Self::MV201), + -53 => Some(Self::MV202), + -52 => Some(Self::MV203), + -51 => Some(Self::MV204), + -50 => Some(Self::MV205), + -49 => Some(Self::MV206), + -48 => Some(Self::MV207), + -47 => Some(Self::MV208), + -46 => Some(Self::MV209), + -45 => Some(Self::MV210), + -44 => Some(Self::MV211), + -43 => Some(Self::MV212), + -42 => Some(Self::MV213), + -41 => Some(Self::MV214), + -40 => Some(Self::MV215), + -39 => Some(Self::MV216), + -38 => Some(Self::MV217), + -37 => Some(Self::MV218), + -36 => Some(Self::MV219), + -35 => Some(Self::MV220), + -34 => Some(Self::MV221), + -33 => Some(Self::MV222), + -32 => Some(Self::MV223), + -31 => Some(Self::MV224), + -30 => Some(Self::MV225), + -29 => Some(Self::MV226), + -28 => Some(Self::MV227), + -27 => Some(Self::MV228), + -26 => Some(Self::MV229), + -25 => Some(Self::MV230), + -24 => Some(Self::MV231), + -23 => Some(Self::MV232), + -22 => Some(Self::MV233), + -21 => Some(Self::MV234), + -20 => Some(Self::MV235), + -19 => Some(Self::MV236), + -18 => Some(Self::MV237), + -17 => Some(Self::MV238), + -16 => Some(Self::MV239), + -15 => Some(Self::MV240), + -14 => Some(Self::MV241), + -13 => Some(Self::MV242), + -12 => Some(Self::MV243), + -11 => Some(Self::MV244), + -10 => Some(Self::MV245), + -9 => Some(Self::MV246), + -8 => Some(Self::MV247), + -7 => Some(Self::MV248), + -6 => Some(Self::MV249), + -5 => Some(Self::MV250), + -4 => Some(Self::MV251), + -3 => Some(Self::MV252), + -2 => Some(Self::MV253), + -1 => Some(Self::MV254), + } + } +} diff --git a/src/enum_impl/mod.rs b/src/enum_impl/mod.rs new file mode 100644 index 0000000..ec0340a --- /dev/null +++ b/src/enum_impl/mod.rs @@ -0,0 +1,44 @@ +pub(crate) mod i8_repr; +pub(crate) mod u8_repr; + +macro_rules! nonmax { + ( $nonmax: ident, $primitive: ident, $byte_repr: ident ) => { + /// An integer that is known not to equal its maximum value. + #[derive(Clone, Copy, PartialEq, Eq, Hash)] + #[repr(transparent)] + pub struct $nonmax($byte_repr); + + impl $nonmax { + /// Creates a new non-max if the given value is not the maximum + /// value. + pub const fn new(value: $primitive) -> Option { + match $byte_repr::new(value) { + Some(byte) => Some(Self(byte)), + None => None, + } + } + + /// Creates a new non-max without checking the value. + /// + /// # Safety + /// + /// The value must not equal the maximum representable value for the + /// primitive type. + #[inline] + pub const unsafe fn new_unchecked(value: $primitive) -> Self { + match Self::new(value) { + Some(this) => this, + None => unsafe { std::hint::unreachable_unchecked() }, + } + } + + /// Returns the value as a primitive type. + #[inline] + pub const fn get(&self) -> $primitive { + self.0 as u8 as $primitive + } + } + }; +} + +pub(crate) use nonmax; diff --git a/src/enum_impl/u8_repr.rs b/src/enum_impl/u8_repr.rs new file mode 100644 index 0000000..c3ccfd3 --- /dev/null +++ b/src/enum_impl/u8_repr.rs @@ -0,0 +1,521 @@ +#[derive(Clone, Copy, PartialEq, Eq, Hash)] +pub(crate) enum U8ByteRepr { + V0 = 0, + V1 = 1, + V2 = 2, + V3 = 3, + V4 = 4, + V5 = 5, + V6 = 6, + V7 = 7, + V8 = 8, + V9 = 9, + V10 = 10, + V11 = 11, + V12 = 12, + V13 = 13, + V14 = 14, + V15 = 15, + V16 = 16, + V17 = 17, + V18 = 18, + V19 = 19, + V20 = 20, + V21 = 21, + V22 = 22, + V23 = 23, + V24 = 24, + V25 = 25, + V26 = 26, + V27 = 27, + V28 = 28, + V29 = 29, + V30 = 30, + V31 = 31, + V32 = 32, + V33 = 33, + V34 = 34, + V35 = 35, + V36 = 36, + V37 = 37, + V38 = 38, + V39 = 39, + V40 = 40, + V41 = 41, + V42 = 42, + V43 = 43, + V44 = 44, + V45 = 45, + V46 = 46, + V47 = 47, + V48 = 48, + V49 = 49, + V50 = 50, + V51 = 51, + V52 = 52, + V53 = 53, + V54 = 54, + V55 = 55, + V56 = 56, + V57 = 57, + V58 = 58, + V59 = 59, + V60 = 60, + V61 = 61, + V62 = 62, + V63 = 63, + V64 = 64, + V65 = 65, + V66 = 66, + V67 = 67, + V68 = 68, + V69 = 69, + V70 = 70, + V71 = 71, + V72 = 72, + V73 = 73, + V74 = 74, + V75 = 75, + V76 = 76, + V77 = 77, + V78 = 78, + V79 = 79, + V80 = 80, + V81 = 81, + V82 = 82, + V83 = 83, + V84 = 84, + V85 = 85, + V86 = 86, + V87 = 87, + V88 = 88, + V89 = 89, + V90 = 90, + V91 = 91, + V92 = 92, + V93 = 93, + V94 = 94, + V95 = 95, + V96 = 96, + V97 = 97, + V98 = 98, + V99 = 99, + V100 = 100, + V101 = 101, + V102 = 102, + V103 = 103, + V104 = 104, + V105 = 105, + V106 = 106, + V107 = 107, + V108 = 108, + V109 = 109, + V110 = 110, + V111 = 111, + V112 = 112, + V113 = 113, + V114 = 114, + V115 = 115, + V116 = 116, + V117 = 117, + V118 = 118, + V119 = 119, + V120 = 120, + V121 = 121, + V122 = 122, + V123 = 123, + V124 = 124, + V125 = 125, + V126 = 126, + V127 = 127, + V128 = 128, + V129 = 129, + V130 = 130, + V131 = 131, + V132 = 132, + V133 = 133, + V134 = 134, + V135 = 135, + V136 = 136, + V137 = 137, + V138 = 138, + V139 = 139, + V140 = 140, + V141 = 141, + V142 = 142, + V143 = 143, + V144 = 144, + V145 = 145, + V146 = 146, + V147 = 147, + V148 = 148, + V149 = 149, + V150 = 150, + V151 = 151, + V152 = 152, + V153 = 153, + V154 = 154, + V155 = 155, + V156 = 156, + V157 = 157, + V158 = 158, + V159 = 159, + V160 = 160, + V161 = 161, + V162 = 162, + V163 = 163, + V164 = 164, + V165 = 165, + V166 = 166, + V167 = 167, + V168 = 168, + V169 = 169, + V170 = 170, + V171 = 171, + V172 = 172, + V173 = 173, + V174 = 174, + V175 = 175, + V176 = 176, + V177 = 177, + V178 = 178, + V179 = 179, + V180 = 180, + V181 = 181, + V182 = 182, + V183 = 183, + V184 = 184, + V185 = 185, + V186 = 186, + V187 = 187, + V188 = 188, + V189 = 189, + V190 = 190, + V191 = 191, + V192 = 192, + V193 = 193, + V194 = 194, + V195 = 195, + V196 = 196, + V197 = 197, + V198 = 198, + V199 = 199, + V200 = 200, + V201 = 201, + V202 = 202, + V203 = 203, + V204 = 204, + V205 = 205, + V206 = 206, + V207 = 207, + V208 = 208, + V209 = 209, + V210 = 210, + V211 = 211, + V212 = 212, + V213 = 213, + V214 = 214, + V215 = 215, + V216 = 216, + V217 = 217, + V218 = 218, + V219 = 219, + V220 = 220, + V221 = 221, + V222 = 222, + V223 = 223, + V224 = 224, + V225 = 225, + V226 = 226, + V227 = 227, + V228 = 228, + V229 = 229, + V230 = 230, + V231 = 231, + V232 = 232, + V233 = 233, + V234 = 234, + V235 = 235, + V236 = 236, + V237 = 237, + V238 = 238, + V239 = 239, + V240 = 240, + V241 = 241, + V242 = 242, + V243 = 243, + V244 = 244, + V245 = 245, + V246 = 246, + V247 = 247, + V248 = 248, + V249 = 249, + V250 = 250, + V251 = 251, + V252 = 252, + V253 = 253, + V254 = 254, +} + +impl U8ByteRepr { + pub(crate) const fn new(value: u8) -> Option { + match value { + 0 => Some(Self::V0), + 1 => Some(Self::V1), + 2 => Some(Self::V2), + 3 => Some(Self::V3), + 4 => Some(Self::V4), + 5 => Some(Self::V5), + 6 => Some(Self::V6), + 7 => Some(Self::V7), + 8 => Some(Self::V8), + 9 => Some(Self::V9), + 10 => Some(Self::V10), + 11 => Some(Self::V11), + 12 => Some(Self::V12), + 13 => Some(Self::V13), + 14 => Some(Self::V14), + 15 => Some(Self::V15), + 16 => Some(Self::V16), + 17 => Some(Self::V17), + 18 => Some(Self::V18), + 19 => Some(Self::V19), + 20 => Some(Self::V20), + 21 => Some(Self::V21), + 22 => Some(Self::V22), + 23 => Some(Self::V23), + 24 => Some(Self::V24), + 25 => Some(Self::V25), + 26 => Some(Self::V26), + 27 => Some(Self::V27), + 28 => Some(Self::V28), + 29 => Some(Self::V29), + 30 => Some(Self::V30), + 31 => Some(Self::V31), + 32 => Some(Self::V32), + 33 => Some(Self::V33), + 34 => Some(Self::V34), + 35 => Some(Self::V35), + 36 => Some(Self::V36), + 37 => Some(Self::V37), + 38 => Some(Self::V38), + 39 => Some(Self::V39), + 40 => Some(Self::V40), + 41 => Some(Self::V41), + 42 => Some(Self::V42), + 43 => Some(Self::V43), + 44 => Some(Self::V44), + 45 => Some(Self::V45), + 46 => Some(Self::V46), + 47 => Some(Self::V47), + 48 => Some(Self::V48), + 49 => Some(Self::V49), + 50 => Some(Self::V50), + 51 => Some(Self::V51), + 52 => Some(Self::V52), + 53 => Some(Self::V53), + 54 => Some(Self::V54), + 55 => Some(Self::V55), + 56 => Some(Self::V56), + 57 => Some(Self::V57), + 58 => Some(Self::V58), + 59 => Some(Self::V59), + 60 => Some(Self::V60), + 61 => Some(Self::V61), + 62 => Some(Self::V62), + 63 => Some(Self::V63), + 64 => Some(Self::V64), + 65 => Some(Self::V65), + 66 => Some(Self::V66), + 67 => Some(Self::V67), + 68 => Some(Self::V68), + 69 => Some(Self::V69), + 70 => Some(Self::V70), + 71 => Some(Self::V71), + 72 => Some(Self::V72), + 73 => Some(Self::V73), + 74 => Some(Self::V74), + 75 => Some(Self::V75), + 76 => Some(Self::V76), + 77 => Some(Self::V77), + 78 => Some(Self::V78), + 79 => Some(Self::V79), + 80 => Some(Self::V80), + 81 => Some(Self::V81), + 82 => Some(Self::V82), + 83 => Some(Self::V83), + 84 => Some(Self::V84), + 85 => Some(Self::V85), + 86 => Some(Self::V86), + 87 => Some(Self::V87), + 88 => Some(Self::V88), + 89 => Some(Self::V89), + 90 => Some(Self::V90), + 91 => Some(Self::V91), + 92 => Some(Self::V92), + 93 => Some(Self::V93), + 94 => Some(Self::V94), + 95 => Some(Self::V95), + 96 => Some(Self::V96), + 97 => Some(Self::V97), + 98 => Some(Self::V98), + 99 => Some(Self::V99), + 100 => Some(Self::V100), + 101 => Some(Self::V101), + 102 => Some(Self::V102), + 103 => Some(Self::V103), + 104 => Some(Self::V104), + 105 => Some(Self::V105), + 106 => Some(Self::V106), + 107 => Some(Self::V107), + 108 => Some(Self::V108), + 109 => Some(Self::V109), + 110 => Some(Self::V110), + 111 => Some(Self::V111), + 112 => Some(Self::V112), + 113 => Some(Self::V113), + 114 => Some(Self::V114), + 115 => Some(Self::V115), + 116 => Some(Self::V116), + 117 => Some(Self::V117), + 118 => Some(Self::V118), + 119 => Some(Self::V119), + 120 => Some(Self::V120), + 121 => Some(Self::V121), + 122 => Some(Self::V122), + 123 => Some(Self::V123), + 124 => Some(Self::V124), + 125 => Some(Self::V125), + 126 => Some(Self::V126), + 127 => Some(Self::V127), + 128 => Some(Self::V128), + 129 => Some(Self::V129), + 130 => Some(Self::V130), + 131 => Some(Self::V131), + 132 => Some(Self::V132), + 133 => Some(Self::V133), + 134 => Some(Self::V134), + 135 => Some(Self::V135), + 136 => Some(Self::V136), + 137 => Some(Self::V137), + 138 => Some(Self::V138), + 139 => Some(Self::V139), + 140 => Some(Self::V140), + 141 => Some(Self::V141), + 142 => Some(Self::V142), + 143 => Some(Self::V143), + 144 => Some(Self::V144), + 145 => Some(Self::V145), + 146 => Some(Self::V146), + 147 => Some(Self::V147), + 148 => Some(Self::V148), + 149 => Some(Self::V149), + 150 => Some(Self::V150), + 151 => Some(Self::V151), + 152 => Some(Self::V152), + 153 => Some(Self::V153), + 154 => Some(Self::V154), + 155 => Some(Self::V155), + 156 => Some(Self::V156), + 157 => Some(Self::V157), + 158 => Some(Self::V158), + 159 => Some(Self::V159), + 160 => Some(Self::V160), + 161 => Some(Self::V161), + 162 => Some(Self::V162), + 163 => Some(Self::V163), + 164 => Some(Self::V164), + 165 => Some(Self::V165), + 166 => Some(Self::V166), + 167 => Some(Self::V167), + 168 => Some(Self::V168), + 169 => Some(Self::V169), + 170 => Some(Self::V170), + 171 => Some(Self::V171), + 172 => Some(Self::V172), + 173 => Some(Self::V173), + 174 => Some(Self::V174), + 175 => Some(Self::V175), + 176 => Some(Self::V176), + 177 => Some(Self::V177), + 178 => Some(Self::V178), + 179 => Some(Self::V179), + 180 => Some(Self::V180), + 181 => Some(Self::V181), + 182 => Some(Self::V182), + 183 => Some(Self::V183), + 184 => Some(Self::V184), + 185 => Some(Self::V185), + 186 => Some(Self::V186), + 187 => Some(Self::V187), + 188 => Some(Self::V188), + 189 => Some(Self::V189), + 190 => Some(Self::V190), + 191 => Some(Self::V191), + 192 => Some(Self::V192), + 193 => Some(Self::V193), + 194 => Some(Self::V194), + 195 => Some(Self::V195), + 196 => Some(Self::V196), + 197 => Some(Self::V197), + 198 => Some(Self::V198), + 199 => Some(Self::V199), + 200 => Some(Self::V200), + 201 => Some(Self::V201), + 202 => Some(Self::V202), + 203 => Some(Self::V203), + 204 => Some(Self::V204), + 205 => Some(Self::V205), + 206 => Some(Self::V206), + 207 => Some(Self::V207), + 208 => Some(Self::V208), + 209 => Some(Self::V209), + 210 => Some(Self::V210), + 211 => Some(Self::V211), + 212 => Some(Self::V212), + 213 => Some(Self::V213), + 214 => Some(Self::V214), + 215 => Some(Self::V215), + 216 => Some(Self::V216), + 217 => Some(Self::V217), + 218 => Some(Self::V218), + 219 => Some(Self::V219), + 220 => Some(Self::V220), + 221 => Some(Self::V221), + 222 => Some(Self::V222), + 223 => Some(Self::V223), + 224 => Some(Self::V224), + 225 => Some(Self::V225), + 226 => Some(Self::V226), + 227 => Some(Self::V227), + 228 => Some(Self::V228), + 229 => Some(Self::V229), + 230 => Some(Self::V230), + 231 => Some(Self::V231), + 232 => Some(Self::V232), + 233 => Some(Self::V233), + 234 => Some(Self::V234), + 235 => Some(Self::V235), + 236 => Some(Self::V236), + 237 => Some(Self::V237), + 238 => Some(Self::V238), + 239 => Some(Self::V239), + 240 => Some(Self::V240), + 241 => Some(Self::V241), + 242 => Some(Self::V242), + 243 => Some(Self::V243), + 244 => Some(Self::V244), + 245 => Some(Self::V245), + 246 => Some(Self::V246), + 247 => Some(Self::V247), + 248 => Some(Self::V248), + 249 => Some(Self::V249), + 250 => Some(Self::V250), + 251 => Some(Self::V251), + 252 => Some(Self::V252), + 253 => Some(Self::V253), + 254 => Some(Self::V254), + 255 => None, + } + } +} diff --git a/src/lib.rs b/src/lib.rs index cb2bbb5..9eaec6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,6 +56,12 @@ will only require minor version bumps, but will need significant justification. #![forbid(missing_docs)] #![cfg_attr(not(feature = "std"), no_std)] +#[macro_use] +mod enum_impl; + +use enum_impl::i8_repr::I8ByteRepr; +use enum_impl::u8_repr::U8ByteRepr; + /// An error type returned when a checked integral type conversion fails (mimics [std::num::TryFromIntError]) #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct TryFromIntError(()); @@ -401,14 +407,17 @@ macro_rules! nonmax_impls { }; } -nonmax_impls!(def, signed, NonMaxI8, NonZeroI8, i8); +enum_impl::nonmax!(NonMaxI8, i8, I8ByteRepr); +enum_impl::nonmax!(NonMaxU8, u8, U8ByteRepr); + +nonmax_impls!(signed, NonMaxI8, NonZeroI8, i8); nonmax_impls!(def, signed, NonMaxI16, NonZeroI16, i16); nonmax_impls!(def, signed, NonMaxI32, NonZeroI32, i32); nonmax_impls!(def, signed, NonMaxI64, NonZeroI64, i64); nonmax_impls!(def, signed, NonMaxI128, NonZeroI128, i128); nonmax_impls!(def, signed, NonMaxIsize, NonZeroIsize, isize); -nonmax_impls!(def, unsigned, NonMaxU8, NonZeroU8, u8); +nonmax_impls!(unsigned, NonMaxU8, NonZeroU8, u8); nonmax_impls!(def, unsigned, NonMaxU16, NonZeroU16, u16); nonmax_impls!(def, unsigned, NonMaxU32, NonZeroU32, u32); nonmax_impls!(def, unsigned, NonMaxU64, NonZeroU64, u64);