1 #![cfg(feature = "alloc")] 2 3 use crate::result::PtrLen; 4 use alloc::boxed::Box; 5 use alloc::string::String; 6 use core::ptr::NonNull; 7 use core::slice; 8 9 #[export_name = "cxxbridge1$exception"] exception(ptr: *const u8, len: usize) -> PtrLen10unsafe extern "C" fn exception(ptr: *const u8, len: usize) -> PtrLen { 11 let slice = unsafe { slice::from_raw_parts(ptr, len) }; 12 let string = String::from_utf8_lossy(slice); 13 let len = string.len(); 14 let raw_str = Box::into_raw(string.into_owned().into_boxed_str()); 15 let raw_u8 = raw_str.cast::<u8>(); 16 let nonnull = unsafe { NonNull::new_unchecked(raw_u8) }; 17 PtrLen { ptr: nonnull, len } 18 } 19