use crate::sys::*;
use std::fmt::{self, Debug};
#[repr(transparent)]
pub struct ZRes {
inner: zend_resource,
}
impl ZRes {
pub unsafe fn from_ptr<'a>(ptr: *const zend_resource) -> &'a Self {
unsafe {
(ptr as *const Self)
.as_ref()
.expect("ptr should not be null")
}
}
pub unsafe fn try_from_ptr<'a>(ptr: *const zend_resource) -> Option<&'a Self> {
unsafe { (ptr as *const Self).as_ref() }
}
pub unsafe fn from_mut_ptr<'a>(ptr: *mut zend_resource) -> &'a mut Self {
unsafe { (ptr as *mut Self).as_mut().expect("ptr should not be null") }
}
pub unsafe fn try_from_mut_ptr<'a>(ptr: *mut zend_resource) -> Option<&'a mut Self> {
unsafe { (ptr as *mut Self).as_mut() }
}
pub const fn as_ptr(&self) -> *const zend_resource {
&self.inner
}
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut zend_resource {
&mut self.inner
}
#[allow(clippy::useless_conversion)]
pub fn handle(&self) -> i64 {
self.inner.handle.into()
}
}
impl Debug for ZRes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ZRes")
.field("handle", &self.handle())
.finish()
}
}