pub struct OpenMptString {
raw: *const std::os::raw::c_char,
}
impl OpenMptString {
pub(crate) fn new(raw: *const std::os::raw::c_char) -> Option<Self> {
Some(Self {
raw: if raw.is_null() {
return None;
} else {
raw
},
})
}
pub fn as_str(&self) -> &str {
unsafe { std::ffi::CStr::from_ptr(self.raw).to_str().unwrap() }
}
}
impl std::fmt::Display for OpenMptString {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl std::fmt::Debug for OpenMptString {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self.as_str())
}
}
impl Drop for OpenMptString {
fn drop(&mut self) {
unsafe {
openmpt_sys::openmpt_free_string(self.raw);
}
}
}