@@ -187,22 +187,23 @@ impl From<i32> for ReturnCode {
187
187
}
188
188
189
189
impl ReturnCode {
190
- const TABLE : [ & ' static str ; 10 ] = [
191
- "need dictionary\0 " , /* Z_NEED_DICT 2 */
192
- "stream end\0 " , /* Z_STREAM_END 1 */
193
- "\0 " , /* Z_OK 0 */
194
- "file error\0 " , /* Z_ERRNO (-1) */
195
- "stream error\0 " , /* Z_STREAM_ERROR (-2) */
196
- "data error\0 " , /* Z_DATA_ERROR (-3) */
197
- "insufficient memory\0 " , /* Z_MEM_ERROR (-4) */
198
- "buffer error\0 " , /* Z_BUF_ERROR (-5) */
199
- "incompatible version\0 " , /* Z_VERSION_ERROR (-6) */
200
- "\0 " ,
201
- ] ;
190
+ const fn error_message_str ( self ) -> & ' static str {
191
+ match self {
192
+ ReturnCode :: Ok => "\0 " ,
193
+ ReturnCode :: StreamEnd => "stream end\0 " ,
194
+ ReturnCode :: NeedDict => "need dictionary\0 " ,
195
+ ReturnCode :: ErrNo => "file error\0 " ,
196
+ ReturnCode :: StreamError => "stream error\0 " ,
197
+ ReturnCode :: DataError => "data error\0 " ,
198
+ ReturnCode :: MemError => "insufficient memory\0 " ,
199
+ ReturnCode :: BufError => "buffer error\0 " ,
200
+ ReturnCode :: VersionError => "incompatible version\0 " ,
201
+ }
202
+ }
202
203
203
204
pub const fn error_message ( self ) -> * const core:: ffi:: c_char {
204
- let index = ( ReturnCode :: NeedDict as i32 - self as i32 ) as usize ;
205
- Self :: TABLE [ index ] . as_ptr ( ) . cast ( )
205
+ let msg = self . error_message_str ( ) ;
206
+ msg . as_ptr ( ) . cast :: < core :: ffi :: c_char > ( )
206
207
}
207
208
208
209
pub const fn try_from_c_int ( err : core:: ffi:: c_int ) -> Option < Self > {
0 commit comments