Skip to content

Commit c858bb9

Browse files
committed
expose error message from stable api
1 parent 636eb37 commit c858bb9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

zlib-rs/src/stable.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ impl Inflate {
8080
u64::from(self.0.total_out)
8181
}
8282

83+
/// The error message if the previous operation failed.
84+
pub fn error_message(&self) -> Option<&'static str> {
85+
if self.0.msg.is_null() {
86+
None
87+
} else {
88+
unsafe { core::ffi::CStr::from_ptr(self.0.msg).to_str() }.ok()
89+
}
90+
}
91+
8392
/// Create a new instance. Note that it allocates in various ways and thus should be re-used.
8493
///
8594
/// The `window_bits` must be in the range `8..=15`, with `15` being most common.
@@ -203,6 +212,15 @@ impl Deflate {
203212
u64::from(self.0.total_out)
204213
}
205214

215+
/// The error message if the previous operation failed.
216+
pub fn error_message(&self) -> Option<&'static str> {
217+
if self.0.msg.is_null() {
218+
None
219+
} else {
220+
unsafe { core::ffi::CStr::from_ptr(self.0.msg).to_str() }.ok()
221+
}
222+
}
223+
206224
/// Create a new instance - this allocates so should be done with care.
207225
///
208226
/// The `window_bits` must be in the range `8..=15`, with `15` being most common.

0 commit comments

Comments
 (0)