diff --git a/libz-rs-sys/src/lib.rs b/libz-rs-sys/src/lib.rs index c6e2e52b..c6481632 100644 --- a/libz-rs-sys/src/lib.rs +++ b/libz-rs-sys/src/lib.rs @@ -96,7 +96,7 @@ pub type z_off_t = c_long; /// } /// ``` #[export_name = prefix!(crc32)] -pub unsafe extern "C" fn crc32(crc: c_ulong, buf: *const Bytef, len: uInt) -> c_ulong { +pub unsafe extern "C-unwind" fn crc32(crc: c_ulong, buf: *const Bytef, len: uInt) -> c_ulong { match unsafe { slice_from_raw_parts(buf, len as usize) } { Some(buf) => zlib_rs::crc32(crc as u32, buf) as c_ulong, None => 0, @@ -131,7 +131,7 @@ pub unsafe extern "C" fn crc32(crc: c_ulong, buf: *const Bytef, len: uInt) -> c_ /// } /// ``` #[export_name = prefix!(crc32_combine)] -pub extern "C" fn crc32_combine(crc1: c_ulong, crc2: c_ulong, len2: z_off_t) -> c_ulong { +pub extern "C-unwind" fn crc32_combine(crc1: c_ulong, crc2: c_ulong, len2: z_off_t) -> c_ulong { zlib_rs::crc32_combine(crc1 as u32, crc2 as u32, len2 as u64) as c_ulong } @@ -161,7 +161,7 @@ pub extern "C" fn crc32_combine(crc1: c_ulong, crc2: c_ulong, len2: z_off_t) -> /// } /// ``` #[export_name = prefix!(adler32)] -pub unsafe extern "C" fn adler32(adler: c_ulong, buf: *const Bytef, len: uInt) -> c_ulong { +pub unsafe extern "C-unwind" fn adler32(adler: c_ulong, buf: *const Bytef, len: uInt) -> c_ulong { match unsafe { slice_from_raw_parts(buf, len as usize) } { Some(buf) => zlib_rs::adler32(adler as u32, buf) as c_ulong, None => 1, @@ -196,7 +196,11 @@ pub unsafe extern "C" fn adler32(adler: c_ulong, buf: *const Bytef, len: uInt) - /// } /// ``` #[export_name = prefix!(adler32_combine)] -pub extern "C" fn adler32_combine(adler1: c_ulong, adler2: c_ulong, len2: z_off_t) -> c_ulong { +pub extern "C-unwind" fn adler32_combine( + adler1: c_ulong, + adler2: c_ulong, + len2: z_off_t, +) -> c_ulong { match u64::try_from(len2) { Ok(len2) => zlib_rs::adler32_combine(adler1 as u32, adler2 as u32, len2) as c_ulong, Err(_) => { @@ -262,7 +266,7 @@ pub extern "C" fn adler32_combine(adler1: c_ulong, adler2: c_ulong, len2: z_off_ /// assert_eq!(dest, b"Ferris"); /// ``` #[export_name = prefix!(uncompress)] -pub unsafe extern "C" fn uncompress( +pub unsafe extern "C-unwind" fn uncompress( dest: *mut u8, destLen: *mut c_ulong, source: *const u8, @@ -311,7 +315,7 @@ pub unsafe extern "C" fn uncompress( /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflate)] -pub unsafe extern "C" fn inflate(strm: *mut z_stream, flush: i32) -> i32 { +pub unsafe extern "C-unwind" fn inflate(strm: *mut z_stream, flush: i32) -> i32 { if let Some(stream) = InflateStream::from_stream_mut(strm) { let flush = InflateFlush::try_from(flush).unwrap_or_default(); zlib_rs::inflate::inflate(stream, flush) as _ @@ -335,7 +339,7 @@ pub unsafe extern "C" fn inflate(strm: *mut z_stream, flush: i32) -> i32 { /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflateEnd)] -pub unsafe extern "C" fn inflateEnd(strm: *mut z_stream) -> i32 { +pub unsafe extern "C-unwind" fn inflateEnd(strm: *mut z_stream) -> i32 { match InflateStream::from_stream_mut(strm) { Some(stream) => { zlib_rs::inflate::end(stream); @@ -369,7 +373,7 @@ pub unsafe extern "C" fn inflateEnd(strm: *mut z_stream) -> i32 { /// - `zfree` /// - `opaque` #[export_name = prefix!(inflateBackInit_)] -pub unsafe extern "C" fn inflateBackInit_( +pub unsafe extern "C-unwind" fn inflateBackInit_( _strm: z_streamp, _windowBits: c_int, _window: *mut c_uchar, @@ -389,7 +393,7 @@ pub unsafe extern "C" fn inflateBackInit_( /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateBackInit_`] #[export_name = prefix!(inflateBack)] -pub unsafe extern "C" fn inflateBack( +pub unsafe extern "C-unwind" fn inflateBack( _strm: z_streamp, _in: in_func, _in_desc: *mut c_void, @@ -416,7 +420,7 @@ pub unsafe extern "C" fn inflateBack( /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateBackInit_`] #[export_name = prefix!(inflateBackEnd)] -pub unsafe extern "C" fn inflateBackEnd(_strm: z_streamp) -> c_int { +pub unsafe extern "C-unwind" fn inflateBackEnd(_strm: z_streamp) -> c_int { todo!("inflateBack is not implemented yet") } @@ -445,7 +449,7 @@ pub unsafe extern "C" fn inflateBackEnd(_strm: z_streamp) -> c_int { /// - `source` is `NULL` /// - `source` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflateCopy)] -pub unsafe extern "C" fn inflateCopy(dest: *mut z_stream, source: *const z_stream) -> i32 { +pub unsafe extern "C-unwind" fn inflateCopy(dest: *mut z_stream, source: *const z_stream) -> i32 { let Some(dest) = (unsafe { dest.cast::>().as_mut() }) else { return ReturnCode::StreamError as _; }; @@ -480,7 +484,7 @@ pub unsafe extern "C" fn inflateCopy(dest: *mut z_stream, source: *const z_strea /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflateMark)] -pub unsafe extern "C" fn inflateMark(strm: *const z_stream) -> c_long { +pub unsafe extern "C-unwind" fn inflateMark(strm: *const z_stream) -> c_long { if let Some(stream) = InflateStream::from_stream_ref(strm) { zlib_rs::inflate::mark(stream) } else { @@ -514,7 +518,7 @@ pub unsafe extern "C" fn inflateMark(strm: *const z_stream) -> c_long { /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflateSync)] -pub unsafe extern "C" fn inflateSync(strm: *mut z_stream) -> i32 { +pub unsafe extern "C-unwind" fn inflateSync(strm: *mut z_stream) -> i32 { if let Some(stream) = InflateStream::from_stream_mut(strm) { zlib_rs::inflate::sync(stream) as _ } else { @@ -531,7 +535,7 @@ pub unsafe extern "C" fn inflateSync(strm: *mut z_stream) -> i32 { /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflateSyncPoint)] -pub unsafe extern "C" fn inflateSyncPoint(strm: *mut z_stream) -> i32 { +pub unsafe extern "C-unwind" fn inflateSyncPoint(strm: *mut z_stream) -> i32 { if let Some(stream) = InflateStream::from_stream_mut(strm) { zlib_rs::inflate::sync_point(stream) as i32 } else { @@ -565,7 +569,7 @@ pub unsafe extern "C" fn inflateSyncPoint(strm: *mut z_stream) -> i32 { /// - `zfree` /// - `opaque` #[export_name = prefix!(inflateInit_)] -pub unsafe extern "C" fn inflateInit_( +pub unsafe extern "C-unwind" fn inflateInit_( strm: z_streamp, version: *const c_char, stream_size: c_int, @@ -598,7 +602,7 @@ pub unsafe extern "C" fn inflateInit_( /// - `zfree` /// - `opaque` #[export_name = prefix!(inflateInit2_)] -pub unsafe extern "C" fn inflateInit2_( +pub unsafe extern "C-unwind" fn inflateInit2_( strm: z_streamp, windowBits: c_int, version: *const c_char, @@ -624,7 +628,7 @@ pub unsafe extern "C" fn inflateInit2_( /// - `zalloc` /// - `zfree` /// - `opaque` -unsafe extern "C" fn inflateInit2(strm: z_streamp, windowBits: c_int) -> c_int { +unsafe extern "C-unwind" fn inflateInit2(strm: z_streamp, windowBits: c_int) -> c_int { let Some(strm) = (unsafe { strm.as_mut() }) else { return ReturnCode::StreamError as _; }; @@ -659,7 +663,7 @@ unsafe extern "C" fn inflateInit2(strm: z_streamp, windowBits: c_int) -> c_int { /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflatePrime)] -pub unsafe extern "C" fn inflatePrime(strm: *mut z_stream, bits: i32, value: i32) -> i32 { +pub unsafe extern "C-unwind" fn inflatePrime(strm: *mut z_stream, bits: i32, value: i32) -> i32 { if let Some(stream) = InflateStream::from_stream_mut(strm) { zlib_rs::inflate::prime(stream, bits, value) as _ } else { @@ -685,7 +689,7 @@ pub unsafe extern "C" fn inflatePrime(strm: *mut z_stream, bits: i32, value: i32 /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflateReset)] -pub unsafe extern "C" fn inflateReset(strm: *mut z_stream) -> i32 { +pub unsafe extern "C-unwind" fn inflateReset(strm: *mut z_stream) -> i32 { if let Some(stream) = InflateStream::from_stream_mut(strm) { zlib_rs::inflate::reset(stream) as _ } else { @@ -712,7 +716,7 @@ pub unsafe extern "C" fn inflateReset(strm: *mut z_stream) -> i32 { /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflateReset2)] -pub unsafe extern "C" fn inflateReset2(strm: *mut z_stream, windowBits: c_int) -> i32 { +pub unsafe extern "C-unwind" fn inflateReset2(strm: *mut z_stream, windowBits: c_int) -> i32 { if let Some(stream) = InflateStream::from_stream_mut(strm) { let config = InflateConfig { window_bits: windowBits, @@ -751,7 +755,7 @@ pub unsafe extern "C" fn inflateReset2(strm: *mut z_stream, windowBits: c_int) - /// - `dictionary` is `NULL` /// - `dictionary` and `dictLength` satisfy the requirements of [`core::slice::from_raw_parts_mut::`] #[export_name = prefix!(inflateSetDictionary)] -pub unsafe extern "C" fn inflateSetDictionary( +pub unsafe extern "C-unwind" fn inflateSetDictionary( strm: *mut z_stream, dictionary: *const u8, dictLength: c_uint, @@ -809,7 +813,7 @@ pub unsafe extern "C" fn inflateSetDictionary( /// - if `head.name` is not NULL, it must be writable for at least `head.name_max` bytes /// - if `head.comment` is not NULL, it must be writable for at least `head.comm_max` bytes #[export_name = prefix!(inflateGetHeader)] -pub unsafe extern "C" fn inflateGetHeader(strm: z_streamp, head: gz_headerp) -> c_int { +pub unsafe extern "C-unwind" fn inflateGetHeader(strm: z_streamp, head: gz_headerp) -> c_int { let Some(stream) = (unsafe { InflateStream::from_stream_mut(strm) }) else { return ReturnCode::StreamError as _; }; @@ -829,7 +833,7 @@ pub unsafe extern "C" fn inflateGetHeader(strm: z_streamp, head: gz_headerp) -> /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflateUndermine)] -pub unsafe extern "C" fn inflateUndermine(strm: *mut z_stream, subvert: i32) -> c_int { +pub unsafe extern "C-unwind" fn inflateUndermine(strm: *mut z_stream, subvert: i32) -> c_int { if let Some(stream) = InflateStream::from_stream_mut(strm) { zlib_rs::inflate::undermine(stream, subvert) as i32 } else { @@ -844,7 +848,7 @@ pub unsafe extern "C" fn inflateUndermine(strm: *mut z_stream, subvert: i32) -> /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`inflateInit_`] or similar #[export_name = prefix!(inflateResetKeep)] -pub unsafe extern "C" fn inflateResetKeep(strm: *mut z_stream) -> c_int { +pub unsafe extern "C-unwind" fn inflateResetKeep(strm: *mut z_stream) -> c_int { if let Some(stream) = InflateStream::from_stream_mut(strm) { zlib_rs::inflate::reset_keep(stream) as _ } else { @@ -863,7 +867,7 @@ pub unsafe extern "C" fn inflateResetKeep(strm: *mut z_stream) -> c_int { /// - `buf` is `NULL` /// - `buf` and `len` satisfy the requirements of [`core::slice::from_raw_parts`] #[export_name = prefix!(inflateCodesUsed)] -pub unsafe extern "C" fn inflateCodesUsed(_strm: *mut z_stream) -> c_ulong { +pub unsafe extern "C-unwind" fn inflateCodesUsed(_strm: *mut z_stream) -> c_ulong { todo!() } @@ -884,7 +888,7 @@ pub unsafe extern "C" fn inflateCodesUsed(_strm: *mut z_stream) -> c_ulong { /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`deflateInit_`] or similar #[export_name = prefix!(deflate)] -pub unsafe extern "C" fn deflate(strm: *mut z_stream, flush: i32) -> c_int { +pub unsafe extern "C-unwind" fn deflate(strm: *mut z_stream, flush: i32) -> c_int { if let Some(stream) = DeflateStream::from_stream_mut(strm) { match DeflateFlush::try_from(flush) { Ok(flush) => zlib_rs::deflate::deflate(stream, flush) as _, @@ -918,7 +922,7 @@ pub unsafe extern "C" fn deflate(strm: *mut z_stream, flush: i32) -> c_int { /// - `head` is `NULL` /// - `head` satisfies the requirements of `&mut *head` #[export_name = prefix!(deflateSetHeader)] -pub unsafe extern "C" fn deflateSetHeader(strm: *mut z_stream, head: gz_headerp) -> c_int { +pub unsafe extern "C-unwind" fn deflateSetHeader(strm: *mut z_stream, head: gz_headerp) -> c_int { let Some(stream) = (unsafe { DeflateStream::from_stream_mut(strm) }) else { return ReturnCode::StreamError as _; }; @@ -944,7 +948,7 @@ pub unsafe extern "C" fn deflateSetHeader(strm: *mut z_stream, head: gz_headerp) /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`deflateInit_`] or similar #[export_name = prefix!(deflateBound)] -pub unsafe extern "C" fn deflateBound(strm: *mut z_stream, sourceLen: c_ulong) -> c_ulong { +pub unsafe extern "C-unwind" fn deflateBound(strm: *mut z_stream, sourceLen: c_ulong) -> c_ulong { zlib_rs::deflate::bound(DeflateStream::from_stream_mut(strm), sourceLen as usize) as c_ulong } @@ -1001,7 +1005,7 @@ pub unsafe extern "C" fn deflateBound(strm: *mut z_stream, sourceLen: c_ulong) - /// assert_eq!(dest, [120, 156, 115, 75, 45, 42, 202, 44, 6, 0, 8, 6, 2, 108]); /// ``` #[export_name = prefix!(compress)] -pub unsafe extern "C" fn compress( +pub unsafe extern "C-unwind" fn compress( dest: *mut Bytef, destLen: *mut c_ulong, source: *const Bytef, @@ -1044,7 +1048,7 @@ pub unsafe extern "C" fn compress( /// - `source` is `NULL` /// - `source` and `sourceLen` satisfy the requirements of [`core::slice::from_raw_parts`] #[export_name = prefix!(compress2)] -pub unsafe extern "C" fn compress2( +pub unsafe extern "C-unwind" fn compress2( dest: *mut Bytef, destLen: *mut c_ulong, source: *const Bytef, @@ -1077,7 +1081,7 @@ pub unsafe extern "C" fn compress2( /// /// Can be used before a [`compress`] or [`compress2`] call to allocate the destination buffer. #[export_name = prefix!(compressBound)] -pub extern "C" fn compressBound(sourceLen: c_ulong) -> c_ulong { +pub extern "C-unwind" fn compressBound(sourceLen: c_ulong) -> c_ulong { zlib_rs::deflate::compress_bound(sourceLen as usize) as c_ulong } @@ -1099,7 +1103,7 @@ pub extern "C" fn compressBound(sourceLen: c_ulong) -> c_ulong { /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`deflateInit_`] or similar #[export_name = prefix!(deflateEnd)] -pub unsafe extern "C" fn deflateEnd(strm: *mut z_stream) -> i32 { +pub unsafe extern "C-unwind" fn deflateEnd(strm: *mut z_stream) -> i32 { match DeflateStream::from_stream_mut(strm) { Some(stream) => match zlib_rs::deflate::end(stream) { Ok(_) => ReturnCode::Ok as _, @@ -1127,7 +1131,7 @@ pub unsafe extern "C" fn deflateEnd(strm: *mut z_stream) -> i32 { /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`deflateInit_`] or similar #[export_name = prefix!(deflateReset)] -pub unsafe extern "C" fn deflateReset(strm: *mut z_stream) -> i32 { +pub unsafe extern "C-unwind" fn deflateReset(strm: *mut z_stream) -> i32 { match DeflateStream::from_stream_mut(strm) { Some(stream) => zlib_rs::deflate::reset(stream) as _, None => ReturnCode::StreamError as _, @@ -1158,7 +1162,11 @@ pub unsafe extern "C" fn deflateReset(strm: *mut z_stream) -> i32 { /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`deflateInit_`] or similar #[export_name = prefix!(deflateParams)] -pub unsafe extern "C" fn deflateParams(strm: z_streamp, level: c_int, strategy: c_int) -> c_int { +pub unsafe extern "C-unwind" fn deflateParams( + strm: z_streamp, + level: c_int, + strategy: c_int, +) -> c_int { let Ok(strategy) = Strategy::try_from(strategy) else { return ReturnCode::StreamError as _; }; @@ -1189,7 +1197,7 @@ pub unsafe extern "C" fn deflateParams(strm: z_streamp, level: c_int, strategy: /// - `dictionary` is `NULL` /// - `dictionary` and `dictLength` satisfy the requirements of [`core::slice::from_raw_parts_mut::`] #[export_name = prefix!(deflateSetDictionary)] -pub unsafe extern "C" fn deflateSetDictionary( +pub unsafe extern "C-unwind" fn deflateSetDictionary( strm: z_streamp, dictionary: *const Bytef, dictLength: uInt, @@ -1225,7 +1233,7 @@ pub unsafe extern "C" fn deflateSetDictionary( /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`deflateInit_`] or similar #[export_name = prefix!(deflatePrime)] -pub unsafe extern "C" fn deflatePrime(strm: z_streamp, bits: c_int, value: c_int) -> c_int { +pub unsafe extern "C-unwind" fn deflatePrime(strm: z_streamp, bits: c_int, value: c_int) -> c_int { match DeflateStream::from_stream_mut(strm) { Some(stream) => zlib_rs::deflate::prime(stream, bits, value) as _, None => ReturnCode::StreamError as _, @@ -1257,7 +1265,7 @@ pub unsafe extern "C" fn deflatePrime(strm: z_streamp, bits: c_int, value: c_int /// - `bits` is `NULL` /// - `bits` satisfies the requirements of [`core::ptr::write::`] #[export_name = prefix!(deflatePending)] -pub unsafe extern "C" fn deflatePending( +pub unsafe extern "C-unwind" fn deflatePending( strm: z_streamp, pending: *mut c_uint, bits: *mut c_int, @@ -1304,7 +1312,7 @@ pub unsafe extern "C" fn deflatePending( /// - `source` is `NULL` /// - `source` satisfies the requirements of `&mut *strm` and was initialized with [`deflateInit_`] or similar #[export_name = prefix!(deflateCopy)] -pub unsafe extern "C" fn deflateCopy(dest: z_streamp, source: z_streamp) -> c_int { +pub unsafe extern "C-unwind" fn deflateCopy(dest: z_streamp, source: z_streamp) -> c_int { let Some(dest) = (unsafe { dest.cast::>().as_mut() }) else { return ReturnCode::StreamError as _; }; @@ -1384,7 +1392,7 @@ pub unsafe extern "C" fn deflateCopy(dest: z_streamp, source: z_streamp) -> c_in /// let strm = unsafe { strm.assume_init_mut() }; /// ``` #[export_name = prefix!(deflateInit_)] -pub unsafe extern "C" fn deflateInit_( +pub unsafe extern "C-unwind" fn deflateInit_( strm: z_streamp, level: c_int, version: *const c_char, @@ -1474,7 +1482,7 @@ pub unsafe extern "C" fn deflateInit_( /// let strm = unsafe { strm.assume_init_mut() }; /// ``` #[export_name = prefix!(deflateInit2_)] -pub unsafe extern "C" fn deflateInit2_( +pub unsafe extern "C-unwind" fn deflateInit2_( strm: z_streamp, level: c_int, method: c_int, @@ -1531,7 +1539,7 @@ pub unsafe extern "C" fn deflateInit2_( /// - `strm` is `NULL` /// - `strm` satisfies the requirements of `&mut *strm` and was initialized with [`deflateInit_`] or similar #[export_name = prefix!(deflateTune)] -pub unsafe extern "C" fn deflateTune( +pub unsafe extern "C-unwind" fn deflateTune( strm: z_streamp, good_length: c_int, max_lazy: c_int, diff --git a/zlib-rs/src/lib.rs b/zlib-rs/src/lib.rs index a9cd499f..922a9b8b 100644 --- a/zlib-rs/src/lib.rs +++ b/zlib-rs/src/lib.rs @@ -187,22 +187,23 @@ impl From for ReturnCode { } impl ReturnCode { - const TABLE: [&'static str; 10] = [ - "need dictionary\0", /* Z_NEED_DICT 2 */ - "stream end\0", /* Z_STREAM_END 1 */ - "\0", /* Z_OK 0 */ - "file error\0", /* Z_ERRNO (-1) */ - "stream error\0", /* Z_STREAM_ERROR (-2) */ - "data error\0", /* Z_DATA_ERROR (-3) */ - "insufficient memory\0", /* Z_MEM_ERROR (-4) */ - "buffer error\0", /* Z_BUF_ERROR (-5) */ - "incompatible version\0", /* Z_VERSION_ERROR (-6) */ - "\0", - ]; + const fn error_message_str(self) -> &'static str { + match self { + ReturnCode::Ok => "\0", + ReturnCode::StreamEnd => "stream end\0", + ReturnCode::NeedDict => "need dictionary\0", + ReturnCode::ErrNo => "file error\0", + ReturnCode::StreamError => "stream error\0", + ReturnCode::DataError => "data error\0", + ReturnCode::MemError => "insufficient memory\0", + ReturnCode::BufError => "buffer error\0", + ReturnCode::VersionError => "incompatible version\0", + } + } pub const fn error_message(self) -> *const core::ffi::c_char { - let index = (ReturnCode::NeedDict as i32 - self as i32) as usize; - Self::TABLE[index].as_ptr().cast() + let msg = self.error_message_str(); + msg.as_ptr().cast::() } pub const fn try_from_c_int(err: core::ffi::c_int) -> Option {