#[unsafe(no_mangle)] extern "C" fn panic() -> ! { panic!("Called panic from external code."); } #[repr(C)] #[derive(Debug, PartialEq, Eq)] pub struct FFISlice { pub ptr: *const u8, pub len: usize, } #[repr(transparent)] #[derive(Debug, PartialEq, Eq)] pub struct MaybeFFISlice { inner: FFISlice, } impl MaybeFFISlice { pub fn is_none(&self) -> bool { self.inner.ptr.is_null() } pub fn into_option(self) -> Option { if self.is_none() { None } else { Some(self.inner) } } } impl FFISlice { pub fn as_slice(&self) -> &[u8] { unsafe { core::slice::from_raw_parts(self.ptr, self.len) } } pub fn as_str(&self) -> &str { unsafe { core::str::from_utf8_unchecked(self.as_slice()) } } }