use super::*;
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct PSTR(pub *mut u8);
impl PSTR {
pub const fn from_raw(ptr: *mut u8) -> Self {
Self(ptr)
}
pub fn null() -> Self {
Self(std::ptr::null_mut())
}
pub fn as_ptr(&self) -> *mut u8 {
self.0
}
pub fn is_null(&self) -> bool {
self.0.is_null()
}
pub unsafe fn as_bytes(&self) -> &[u8] {
let len = super::strlen(PCSTR::from_raw(self.0));
std::slice::from_raw_parts(self.0, len)
}
pub unsafe fn to_string(&self) -> std::result::Result<String, std::string::FromUtf8Error> {
String::from_utf8(self.as_bytes().into())
}
pub unsafe fn display(&self) -> impl std::fmt::Display + '_ {
Decode(move || decode_utf8(self.as_bytes()))
}
}
impl TypeKind for PSTR {
type TypeKind = CopyType;
}