1#![cfg(feature = "alloc")] 2 3use crate::result::PtrLen; 4use alloc::boxed::Box; 5use alloc::string::String; 6use core::ptr::NonNull; 7use core::slice; 8 9#[export_name = "cxxbridge1$exception"] 10unsafe 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